Skip to content

Commit

Permalink
faster
Browse files Browse the repository at this point in the history
  • Loading branch information
glguy committed Dec 16, 2023
1 parent aab7833 commit 6005385
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions solutions/src/2023/16.hs
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,12 @@ dfsOn p rep next start = loop IntSet.empty [start]
loop !seen = \case
[] -> []
x : q
| IntSet.member r seen -> loop seen q
| otherwise -> x : loop seen' q'
| slow, IntSet.member r seen -> loop seen q
| otherwise -> x : loop seen' q'
where
slow = p x
r = rep x
seen' = if p x then IntSet.insert r seen else seen
seen' = if slow then IntSet.insert r seen else seen
q' = next x ++ q

-- A more efficient way to count the number of unique coordinates
Expand Down

0 comments on commit 6005385

Please sign in to comment.