Compare commits

..

5 commits

Author SHA1 Message Date
eriedaberrie bab443b919 2023 day 8: add Haskell solution 2023-12-07 23:10:02 -08:00
eriedaberrie 6e95a83496 2023 day 8 2023-12-07 21:31:28 -08:00
eriedaberrie 97e2498f48 2023 day 7: add Haskell solution 2023-12-07 19:10:06 -08:00
eriedaberrie 0fb297fc27 Add GPL license 2023-12-06 23:34:57 -08:00
eriedaberrie 625194d041 Add nix stuff 2023-12-06 23:31:00 -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 n
| s == "ZZZ" = n
| otherwise = countTimes' ds (getDirection d $ m HMS.! s) (succ n)
countTimes' (d:ds) s
| s == "ZZZ" = id
| otherwise = countTimes' ds (getDirection d $ m HMS.! s) . succ
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:_) n
| s == 'Z' = n
| otherwise = countTimes' ds (getDirection d $ m HMS.! ss) (succ n)
countTimes' (d:ds) ss@(s:_)
| s == 'Z' = id
| otherwise = countTimes' ds (getDirection d $ m HMS.! ss) . succ
solve :: String -> DataMap -> Int
solve directions m = foldl1' lcm $ map (countTimes directions m) $ filter ((== 'A') . head) $ HMS.keys m