projects
/
advent-of-code-22.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Tidying
[advent-of-code-22.git]
/
advent22
/
Main.hs
diff --git
a/advent22/Main.hs
b/advent22/Main.hs
index 1a2e1c7eb67281b52f3c35f3a3564f77ca5d2bb3..848be83e062923f8148bd79046cfc307411d884f 100644
(file)
--- a/
advent22/Main.hs
+++ b/
advent22/Main.hs
@@
-2,6
+2,7
@@
-- import Debug.Trace
-- import Debug.Trace
+
import AoC
import Prelude hiding (Left, Right)
import qualified Data.Map.Strict as M
import AoC
import Prelude hiding (Left, Right)
import qualified Data.Map.Strict as M
@@
-253,13
+254,16
@@
isCell r c rows = isRow && isCol && ((rows !! r) !! c) `elem` (".#" :: String)
where isRow = r < length rows
isCol = c < (length $ rows !! r)
where isRow = r < length rows
isCol = c < (length $ rows !! r)
-mkInstructions :: String -> [PathElement]
+mkInstructions
, mkWalk, mkTurn
:: String -> [PathElement]
mkInstructions [] = []
mkInstructions [] = []
-mkInstructions text@(t:
ts
)
+mkInstructions text@(t:
_
)
| isDigit t = mkWalk text
| otherwise = mkTurn text
| isDigit t = mkWalk text
| otherwise = mkTurn text
+
mkWalk text = (Forward $ read digits) : (mkInstructions remainder)
where (digits, remainder) = span (isDigit) text
mkWalk text = (Forward $ read digits) : (mkInstructions remainder)
where (digits, remainder) = span (isDigit) text
+
+mkTurn [] = []
mkTurn (t:ts)
| t == 'R' = Clockwise : (mkInstructions ts)
| t == 'L' = Anticlockwise : (mkInstructions ts)
mkTurn (t:ts)
| t == 'R' = Clockwise : (mkInstructions ts)
| t == 'L' = Anticlockwise : (mkInstructions ts)