Tidying, mainly parsers
[advent-of-code-23.git] / advent08 / Main.hs
index b2c9895b9929f4a922bb4e51c25fe83a39c291c3..5ab2916ced95bbdf93ebe3c6b3e7667f108c33d0 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
@@ -103,13 +103,13 @@ desertLineP :: Parser (String, Node)
 nodeP :: Parser Node
 nameP :: Parser String
 
-problemP = (,) <$> ((many1 directionP) <* many1 endOfLine) <*> desertP
+problemP = (,) <$> many1 directionP <* many1 endOfLine <*> desertP
 directionP = (L <$ "L") <|> (R <$ "R")
 
 desertP = M.fromList <$> desertLineP `sepBy` endOfLine
-desertLineP = (,) <$> (nameP <* " = ") <*> nodeP
+desertLineP = (,) <$> nameP <* " = " <*> nodeP
 
-nodeP = Node <$> ("(" *> nameP <* ", ") <*> (nameP <* ")")
+nodeP = Node <$ "(" <*> nameP <* ", " <*> nameP <* ")"
 nameP = many1 (letter <|> digit) 
 
 successfulParse :: Text -> ([Direction], Desert)