X-Git-Url: https://git.njae.me.uk/?p=advent-of-code-19.git;a=blobdiff_plain;f=advent17%2Fsrc%2Fadvent17.hs;h=781b2e9a041a366d484505f7430680d21eab28f9;hp=34d80a96974c4428ebac137537ac4bc184ba948c;hb=d5e7b65eb2a47c9142530adfae52f30930cbf6ae;hpb=9844d5dc55ae2c14ad66ae3708518535fa6107dc diff --git a/advent17/src/advent17.hs b/advent17/src/advent17.hs index 34d80a9..781b2e9 100644 --- a/advent17/src/advent17.hs +++ b/advent17/src/advent17.hs @@ -99,21 +99,20 @@ alignmentParam (r, c) = r * c findRoutine :: ScaffoldBuilder -> Routine findRoutine scaff = head $ compressedCmds - where -- scaff = mkVisited sb - path = findPath scaff + where path = findPath scaff cmds = toCommands path compressedCmds = compress cmds -encodeRoutine :: ([Command], [Command], [Command], [Command]) -> [Integer] +encodeRoutine :: Routine -> [Integer] encodeRoutine (abc, a, b, c) = map (fromIntegral . ord) $ unlines [show abc, show a, show b, show c, "n", ""] + findPath :: ScaffoldBuilder -> [Step] findPath = unfoldr takeStep takeStep :: ScaffoldBuilder -> Maybe (Step, ScaffoldBuilder) takeStep visitedScaffold = step where scaff = _scaffold visitedScaffold - -- visited = _visited visitedScaffold here = _droidPos visitedScaffold dir = _droidDirection visitedScaffold fPos = ahead here dir @@ -162,6 +161,7 @@ compress commands = guard $ length (show c) <= 20 let commandsABC = replace c C commandsAB guard $ length (show commandsABC) <= 20 + guard $ onlyNonBase commandsABC return (commandsABC, a, b, c) @@ -177,6 +177,9 @@ replace moves label commands = onlyBase :: [Command] -> Bool onlyBase moves = all isBase moves +onlyNonBase :: [Command] -> Bool +onlyNonBase moves = all (not . isBase) moves + isBase :: Command -> Bool isBase (FN _) = True isBase L = True