From: Neil Smith Date: Thu, 22 Dec 2022 22:32:06 +0000 (+0000) Subject: Small tweaks X-Git-Url: https://git.njae.me.uk/?a=commitdiff_plain;h=88d1ab058232b5590f33871b569fed9b0b9bed7c;p=advent-of-code-22.git Small tweaks --- 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