-- 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)
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