Implement day 15, in Haskell.

This commit is contained in:
2017-12-16 23:38:17 +01:00
parent 56fb300d3b
commit 924c76c3b3
3 changed files with 27 additions and 2 deletions

3
2017/day-15/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
solution
solution.hi
solution.o

22
2017/day-15/solution.hs Normal file
View File

@@ -0,0 +1,22 @@
import Data.Bits
genA n = n : genA ((n * 16807) `rem` 2147483647)
genB n = n : genB ((n * 48271) `rem` 2147483647)
judge :: (Integer, Integer) -> Bool
judge (a, b) = (a .&. 0xffff) == (b .&. 0xffff)
divisible :: Integer -> Integer -> Bool
divisible b = (== 0) . (`rem` b)
genA' n = filter (divisible 4) $ genA n
genB' n = filter (divisible 8) $ genB n
main :: IO ()
main = do
let aStart = 618
let bStart = 814
print $ length $ filter judge $ take 40000000 $ drop 1 $ zip (genA aStart) (genB bStart)
print $ length $ filter judge $ take 5000000 $ zip (genA' aStart) (genB' bStart)