aboutsummaryrefslogtreecommitdiff
path: root/Puzzle15.hs
diff options
context:
space:
mode:
authorYuchen Pei <me@ypei.me>2017-12-16 09:46:08 +0100
committerYuchen Pei <me@ypei.me>2017-12-16 09:46:08 +0100
commit2ee661b014861911dc22a85c10f5fc37c7c2bf77 (patch)
tree1dc48161156a73f005ef7227b44cd3427cb2217a /Puzzle15.hs
parent8b79480eac1406524032cab6d0cc3bb5f3ab5e3f (diff)
finished a bit of puzzle 16, attempted puzzle 15
Diffstat (limited to 'Puzzle15.hs')
-rw-r--r--Puzzle15.hs24
1 files changed, 24 insertions, 0 deletions
diff --git a/Puzzle15.hs b/Puzzle15.hs
new file mode 100644
index 0000000..104e2aa
--- /dev/null
+++ b/Puzzle15.hs
@@ -0,0 +1,24 @@
+import Data.Int
+
+stepA :: Int64 -> Int64
+stepA x = x * 16807 `mod` 2147483647
+stepB :: Int64 -> Int64
+stepB x = x * 48271 `mod` 2147483647
+
+toInt16 :: Int64 -> Int16
+toInt16 = fromIntegral
+
+stepAB :: ((Int64, Int64), Int) -> ((Int64, Int64), Int)
+stepAB ((x, y), n) = ((stepA x, stepB y), if (toInt16 x) == (toInt16 y) then n + 1 else n)
+
+solve1' :: ((Int64, Int64), Int) -> Int -> ((Int64, Int64), Int)
+solve1' z 0 = z
+solve1' z m = let !w = stepAB z in let !m' = m - 1 in solve1' w m'
+
+solve1 :: (Int64, Int64) -> Int
+solve1 (x, y) = snd $ solve1' ((x, y), 0) 40000000
+
+input :: (Int64, Int64)
+input = (783, 325)
+
+main = (putStrLn . show . solve1) input