Compare commits
5 commits
bab443b919
...
a9bf16012d
Author | SHA1 | Date | |
---|---|---|---|
a9bf16012d | |||
7b493f2420 | |||
985b91b61c | |||
16e6d52927 | |||
36dba1e373 |
|
@ -9,9 +9,9 @@ getDirection 'R' = snd
|
||||||
countTimes :: String -> DataMap -> Int
|
countTimes :: String -> DataMap -> Int
|
||||||
countTimes directions m = countTimes' directions "AAA" 0
|
countTimes directions m = countTimes' directions "AAA" 0
|
||||||
where
|
where
|
||||||
countTimes' (d:ds) s
|
countTimes' (d:ds) s n
|
||||||
| s == "ZZZ" = id
|
| s == "ZZZ" = n
|
||||||
| otherwise = countTimes' ds (getDirection d $ m HMS.! s) . succ
|
| otherwise = countTimes' ds (getDirection d $ m HMS.! s) (succ n)
|
||||||
|
|
||||||
getDataMap :: [String] -> DataMap
|
getDataMap :: [String] -> DataMap
|
||||||
getDataMap = HMS.fromList . map parseLine
|
getDataMap = HMS.fromList . map parseLine
|
||||||
|
|
|
@ -10,9 +10,9 @@ getDirection 'R' = snd
|
||||||
countTimes :: String -> DataMap -> String -> Int
|
countTimes :: String -> DataMap -> String -> Int
|
||||||
countTimes directions m start = countTimes' directions start 0
|
countTimes directions m start = countTimes' directions start 0
|
||||||
where
|
where
|
||||||
countTimes' (d:ds) ss@(s:_)
|
countTimes' (d:ds) ss@(s:_) n
|
||||||
| s == 'Z' = id
|
| s == 'Z' = n
|
||||||
| otherwise = countTimes' ds (getDirection d $ m HMS.! ss) . succ
|
| otherwise = countTimes' ds (getDirection d $ m HMS.! ss) (succ n)
|
||||||
|
|
||||||
solve :: String -> DataMap -> Int
|
solve :: String -> DataMap -> Int
|
||||||
solve directions m = foldl1' lcm $ map (countTimes directions m) $ filter ((== 'A') . head) $ HMS.keys m
|
solve directions m = foldl1' lcm $ map (countTimes directions m) $ filter ((== 'A') . head) $ HMS.keys m
|
||||||
|
|
Loading…
Reference in a new issue