-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.hs
More file actions
30 lines (22 loc) · 738 Bytes
/
run.hs
File metadata and controls
30 lines (22 loc) · 738 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeApplications #-}
import AoC
import AoC.Grid
import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as HashMap
parseAll input = read @[Int] $ "[" ++ input ++ "]"
lantern = iterate go
where go = HashMap.fromListWith (+) . concatMap f . HashMap.toList
f (0, !n) = [(6, n), (8, n)]
f (i, !n) = [(i - 1, n)]
simulate = lantern . HashMap.fromListWith (+) . map (,1)
part1 = sum . (!! 80) . simulate
part2 = sum . (!! 256) . simulate
main = main' "input.txt"
exampleMain = main' "example.txt"
main' file = do
input <- parseAll <$> readFile file
print (part1 input)
print (part2 input)