X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=advent08%2FMain.hs;h=b2c9895b9929f4a922bb4e51c25fe83a39c291c3;hb=320c134b0e7dd42100c71316223f56c4682b954f;hp=90f596d0359e317bf18193900ef62db4df88a5f0;hpb=2112fa6fd0099dabee1c0ed9890ee3a381fbc03c;p=advent-of-code-23.git diff --git a/advent08/Main.hs b/advent08/Main.hs index 90f596d..b2c9895 100644 --- a/advent08/Main.hs +++ b/advent08/Main.hs @@ -31,7 +31,7 @@ main = -- print $ desert print $ part1 desert directions print $ part2 desert directions - -- print $ part3 desert directions + print $ part3 desert directions part1, part2 :: Desert -> [Direction] -> Int part1 desert directions = getSteps $ walk desert directions (State "AAA" 0) @@ -50,16 +50,16 @@ generateRouteLengths desert directions = M.unions ((fmap snd sResults) ++ (fmap gResults = fmap (walkWithCache desert directions M.empty) fromGoals --- part3 desert directions = multiWalk desert directions M.empty starts --- where starts = fmap (\s -> State s 0) $ startsOf desert +part3 desert directions = multiWalk desert directions M.empty starts + where starts = fmap (\s -> State s 0) $ startsOf desert --- multiWalk desert directions cache states@(s:ss) --- | (all isGoal states) && (sameTime states) = states --- | otherwise = multiWalk desert directions newCache $ sort (s':ss) --- where (s', newCache) = walkWithCache desert directions cache s +multiWalk desert directions cache states@(s:ss) + | (all isGoal states) && (sameTime states) = states + | otherwise = multiWalk desert directions newCache $ sort (s':ss) + where (s', newCache) = walkWithCache desert directions cache s --- sameTime states = (length $ nub times) == 1 --- where times = fmap getSteps states +sameTime states = (length $ nub times) == 1 + where times = fmap getSteps states walk :: Desert -> [Direction] -> State -> State walk desert directions start = head $ dropWhile (not . isGoal) path