aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.Puzzle15.hs.swobin0 -> 12288 bytes
-rwxr-xr-xPuzzle15bin0 -> 22680 bytes
-rw-r--r--Puzzle15.hibin0 -> 1201 bytes
-rw-r--r--Puzzle15.hs24
-rw-r--r--Puzzle15.obin0 -> 12328 bytes
-rw-r--r--Puzzle16.hs15
6 files changed, 39 insertions, 0 deletions
diff --git a/.Puzzle15.hs.swo b/.Puzzle15.hs.swo
new file mode 100644
index 0000000..7290ce3
--- /dev/null
+++ b/.Puzzle15.hs.swo
Binary files differ
diff --git a/Puzzle15 b/Puzzle15
new file mode 100755
index 0000000..5b98560
--- /dev/null
+++ b/Puzzle15
Binary files differ
diff --git a/Puzzle15.hi b/Puzzle15.hi
new file mode 100644
index 0000000..2df21fd
--- /dev/null
+++ b/Puzzle15.hi
Binary files differ
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
diff --git a/Puzzle15.o b/Puzzle15.o
new file mode 100644
index 0000000..0303362
--- /dev/null
+++ b/Puzzle15.o
Binary files differ
diff --git a/Puzzle16.hs b/Puzzle16.hs
new file mode 100644
index 0000000..a15f802
--- /dev/null
+++ b/Puzzle16.hs
@@ -0,0 +1,15 @@
+import Data.List (elemIndex)
+import Data.Maybe (fromJust)
+
+spin n xs = let (ys, zs) = splitAt n xs in zs ++ ys
+
+exchange m n xs
+ | n > m = ys ++ [y] ++ zs ++ [x] ++ ws
+ | n == m = xs
+ | otherwise = exchange n m xs
+ where (ys, x:xs') = splitAt m xs
+ (zs, y:ws) = splitAt (n - m - 1) xs'
+
+partner x y xs = exchange m n xs
+ where m = fromJust $ elemIndex x xs
+ n = fromJust $ elemIndex y xs