Done day 9
[advent-of-code-23.git] / advent08 / Main.hs
index 90f596d0359e317bf18193900ef62db4df88a5f0..b2c9895b9929f4a922bb4e51c25fe83a39c291c3 100644 (file)
@@ -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