Compare commits

..

5 commits

Author SHA1 Message Date
eriedaberrie a9bf16012d 2023 day 8: add Haskell solution 2023-12-07 23:10:18 -08:00
eriedaberrie 7b493f2420 2023 day 8 2023-12-07 21:31:28 -08:00
eriedaberrie 985b91b61c 2023 day 7: add Haskell solution 2023-12-07 19:10:27 -08:00
eriedaberrie 16e6d52927 Add GPL license 2023-12-06 23:34:57 -08:00
eriedaberrie 36dba1e373 Add nix stuff 2023-12-06 23:34:04 -08:00
2 changed files with 6 additions and 6 deletions

View file

@ -9,9 +9,9 @@ getDirection 'R' = snd
countTimes :: String -> DataMap -> Int
countTimes directions m = countTimes' directions "AAA" 0
where
countTimes' (d:ds) s
| s == "ZZZ" = id
| otherwise = countTimes' ds (getDirection d $ m HMS.! s) . succ
countTimes' (d:ds) s n
| s == "ZZZ" = n
| otherwise = countTimes' ds (getDirection d $ m HMS.! s) (succ n)
getDataMap :: [String] -> DataMap
getDataMap = HMS.fromList . map parseLine

View file

@ -10,9 +10,9 @@ getDirection 'R' = snd
countTimes :: String -> DataMap -> String -> Int
countTimes directions m start = countTimes' directions start 0
where
countTimes' (d:ds) ss@(s:_)
| s == 'Z' = id
| otherwise = countTimes' ds (getDirection d $ m HMS.! ss) . succ
countTimes' (d:ds) ss@(s:_) n
| s == 'Z' = n
| otherwise = countTimes' ds (getDirection d $ m HMS.! ss) (succ n)
solve :: String -> DataMap -> Int
solve directions m = foldl1' lcm $ map (countTimes directions m) $ filter ((== 'A') . head) $ HMS.keys m