X-Git-Url: https://git.njae.me.uk/?p=advent-of-code-22.git;a=blobdiff_plain;f=advent22%2FMain.hs;fp=advent22%2FMain.hs;h=848be83e062923f8148bd79046cfc307411d884f;hp=1a2e1c7eb67281b52f3c35f3a3564f77ca5d2bb3;hb=3ad0f674265f18dc390d3d6078348cea5f36f98c;hpb=402a27d38485107852e8128f20a443cc7a684c6d diff --git a/advent22/Main.hs b/advent22/Main.hs index 1a2e1c7..848be83 100644 --- a/advent22/Main.hs +++ b/advent22/Main.hs @@ -2,6 +2,7 @@ -- import Debug.Trace + 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) -mkInstructions :: String -> [PathElement] +mkInstructions, mkWalk, mkTurn :: String -> [PathElement] mkInstructions [] = [] -mkInstructions text@(t:ts) +mkInstructions text@(t:_) | isDigit t = mkWalk text | otherwise = mkTurn 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)