projects
/
advent-of-code-19.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
9844d5d
)
Tidying
author
Neil Smith
<neil.git@njae.me.uk>
Sun, 22 Dec 2019 23:21:59 +0000
(23:21 +0000)
committer
Neil Smith
<neil.git@njae.me.uk>
Sun, 22 Dec 2019 23:21:59 +0000
(23:21 +0000)
advent17/src/advent17.hs
patch
|
blob
|
history
diff --git
a/advent17/src/advent17.hs
b/advent17/src/advent17.hs
index 34d80a96974c4428ebac137537ac4bc184ba948c..781b2e9a041a366d484505f7430680d21eab28f9 100644
(file)
--- 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
findRoutine :: ScaffoldBuilder -> Routine
findRoutine scaff = head $ compressedCmds
- where -- scaff = mkVisited sb
- path = findPath scaff
+ where path = findPath scaff
cmds = toCommands path
compressedCmds = compress cmds
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", ""]
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
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
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 $ length (show c) <= 20
let commandsABC = replace c C commandsAB
guard $ length (show commandsABC) <= 20
+ guard $ onlyNonBase commandsABC
return (commandsABC, a, b, c)
return (commandsABC, a, b, c)
@@
-177,6
+177,9
@@
replace moves label commands =
onlyBase :: [Command] -> Bool
onlyBase moves = all isBase moves
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
isBase :: Command -> Bool
isBase (FN _) = True
isBase L = True