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 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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue