projects
/
advent-of-code-22.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
ea35652
)
Small tweaks
author
Neil Smith
<NeilNjae@users.noreply.github.com>
Thu, 22 Dec 2022 22:32:06 +0000
(22:32 +0000)
committer
Neil Smith
<NeilNjae@users.noreply.github.com>
Thu, 22 Dec 2022 22:32:06 +0000
(22:32 +0000)
advent22/Main.hs
patch
|
blob
|
history
diff --git
a/advent22/Main.hs
b/advent22/Main.hs
index 93af26916a4a5e139f484816c96ddd061a4fdae1..17f66898e93c286d9438e42dd3656f3f718c5a36 100644
(file)
--- a/
advent22/Main.hs
+++ b/
advent22/Main.hs
@@
-44,7
+44,10
@@
data Person = Person {_position :: Position, _facing :: Direction}
deriving (Show, Eq)
makeLenses ''Person
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
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
mkFlatField fieldMap =
Field { getMap = fieldMap
, whatsAheadFunc = whatsAheadFlat
- , whatsAtFunc = whatsAt}
+ -- , whatsAtFunc = whatsAt
+ }
mkCubeField :: FieldMap -> Field
mkCubeField fieldMap =
Field { getMap = fieldMap
, whatsAheadFunc = whatsAheadCube
mkCubeField :: FieldMap -> Field
mkCubeField fieldMap =
Field { getMap = fieldMap
, whatsAheadFunc = whatsAheadCube
- , whatsAtFunc = whatsAt}
+ -- , whatsAtFunc = whatsAt
+ }
whatsAt :: Position -> FieldContext Cell
whatsAt posiiton =
whatsAt :: Position -> FieldContext Cell
whatsAt posiiton =
@@
-203,10
+208,7
@@
crossEdge person face =
walk :: Person -> [PathElement] -> FieldContext Person
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)
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
| otherwise =
do whatsAhead <- asks whatsAheadFunc
person' <- whatsAhead person
- whatsAt <- asks whatsAtFunc
+
--
whatsAt <- asks whatsAtFunc
nextCell <- whatsAt (person' ^. position)
if nextCell == Wall
then return person
nextCell <- whatsAt (person' ^. position)
if nextCell == Wall
then return person