Skip to content

Commit

Permalink
simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
glguy committed Dec 23, 2023
1 parent cadda5e commit 9c27a67
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions solutions/src/2023/23.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,11 @@ buildPaths input isOpen = go [C 0 1] Map.empty
where
(_, C ymax _) = bounds input

exits here there =
[
next
| next <- cardinal here
, next /= there
, cell <- arrIx input next
, isOpen cell (next - here)
adj here =
[ next
| next <- cardinal here
, cell <- arrIx input next
, isOpen cell (next - here)
]

go [] acc = acc
Expand All @@ -63,15 +61,11 @@ buildPaths input isOpen = go [C 0 1] Map.empty
| otherwise = go (map fst nodes ++ xs) (Map.insert x nodes acc)
where
nodes =
[ out
| c <- cardinal x
, cell <- arrIx input c
, isOpen cell (c - x)
, out <- walk c x 1
]
do c <- adj x
walk c x 1

walk here there dist =
case exits here there of
case filter (there /=) (adj here) of
[next] | coordRow next /= ymax -> walk next here (dist+1)
_ -> [(here, dist)]

Expand Down

0 comments on commit 9c27a67

Please sign in to comment.