From d5e7b65eb2a47c9142530adfae52f30930cbf6ae Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Sun, 22 Dec 2019 23:21:59 +0000 Subject: [PATCH] Tidying --- advent17/src/advent17.hs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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 -- 2.34.1