aboutsummaryrefslogtreecommitdiff
path: root/execs/Day15.hs
diff options
context:
space:
mode:
Diffstat (limited to 'execs/Day15.hs')
-rw-r--r--execs/Day15.hs21
1 files changed, 21 insertions, 0 deletions
diff --git a/execs/Day15.hs b/execs/Day15.hs
new file mode 100644
index 0000000..cd498fb
--- /dev/null
+++ b/execs/Day15.hs
@@ -0,0 +1,21 @@
1module Main where
2
3import Data.Maybe
4import Data.List.Split
5import qualified Data.Map as M
6
7run :: [Int] -> Int -> [Int] -> Int
8run ls start input = fst $ foldl fn (start, startMap) ls
9 where startMap = M.fromList $ zip input [1..]
10 fn (last, seen) i = (i - last', seen')
11 where last' = fromMaybe i (M.lookup last seen)
12 seen' = M.insert last i seen
13
14main :: IO ()
15main = do
16 n <- map read . splitOn "," <$> readFile "input/15"
17
18 -- holy off-by-one errors
19 print $ run [8..2020 - 1] 0 n
20 print $ run [8..30000000 - 1] 0 n
21