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=17f66898e93c286d9438e42dd3656f3f718c5a36;hp=93af26916a4a5e139f484816c96ddd061a4fdae1;hb=88d1ab058232b5590f33871b569fed9b0b9bed7c;hpb=ea35652beea3aa2e32ae15c13388d893b0044e1a

diff --git a/advent22/Main.hs b/advent22/Main.hs
index 93af269..17f6689 100644
--- a/advent22/Main.hs
+++ b/advent22/Main.hs
@@ -44,7 +44,10 @@ data Person = Person {_position :: Position, _facing :: Direction}
   deriving (Show, Eq)
 makeLenses ''Person
 
-data Field = Field { getMap :: FieldMap, whatsAheadFunc :: Person -> FieldContext Person, whatsAtFunc :: Position -> FieldContext Cell}
+data Field = Field { getMap :: FieldMap
+                   , whatsAheadFunc :: Person -> FieldContext Person
+                   -- , whatsAtFunc :: Position -> FieldContext Cell
+                   }
 type FieldContext = Reader Field
 
 data Face = A | B | C | D | E | F
@@ -100,14 +103,16 @@ mkFlatField :: FieldMap -> Field
 mkFlatField fieldMap = 
   Field { getMap = fieldMap
         , whatsAheadFunc = whatsAheadFlat
-        , whatsAtFunc = whatsAt}
+        -- , whatsAtFunc = whatsAt
+        }
 
 
 mkCubeField :: FieldMap -> Field
 mkCubeField fieldMap = 
   Field { getMap = fieldMap
         , whatsAheadFunc = whatsAheadCube
-        , whatsAtFunc = whatsAt}
+        -- , whatsAtFunc = whatsAt
+        }
 
 whatsAt :: Position -> FieldContext Cell
 whatsAt posiiton =
@@ -203,10 +208,7 @@ crossEdge person face =
 
 
 walk :: Person -> [PathElement] -> FieldContext Person
-walk person [] = return person
-walk person (step:steps) = 
-  do person' <- walkOne person step
-     walk person' steps
+walk person path = foldM walkOne person path
 
 walkOne :: Person -> PathElement -> FieldContext Person
 walkOne person (Forward n) 
@@ -214,7 +216,7 @@ walkOne person (Forward n)
   | otherwise = 
       do whatsAhead <- asks whatsAheadFunc
          person' <- whatsAhead person
-         whatsAt <- asks whatsAtFunc
+         -- whatsAt <- asks whatsAtFunc
          nextCell <- whatsAt (person' ^. position)
          if nextCell == Wall 
          then return person