diff options
Diffstat (limited to 'execs/Day15.hs')
-rw-r--r-- | execs/Day15.hs | 21 |
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 @@ | |||
1 | module Main where | ||
2 | |||
3 | import Data.Maybe | ||
4 | import Data.List.Split | ||
5 | import qualified Data.Map as M | ||
6 | |||
7 | run :: [Int] -> Int -> [Int] -> Int | ||
8 | run 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 | |||
14 | main :: IO () | ||
15 | main = 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 | |||