Skip to content

Commit

Permalink
Day 4: Weird foldr instead of recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
amalloy committed Dec 6, 2021
1 parent 901eecf commit 750f831
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions day04/src/Main.hs
Expand Up @@ -47,9 +47,8 @@ winner (Board b) = winningRow b || winningRow (sequenceA b)
where winningRow = any (all isNothing)

states :: Input -> [State]
states (Input nums boards) = go nums (fmap (fmap Just) boards)
where go [] _ = []
go (n:ns) boards = State n boards' : go ns (filter (not . winner) boards')
states (Input nums boards) = foldr go (const []) nums (fmap (fmap Just) boards)
where go n acc boards = State n boards' : acc (filter (not . winner) boards')
where boards' = mark n <$> boards

score :: Num a => a -> Board (Maybe a) -> a
Expand Down

0 comments on commit 750f831

Please sign in to comment.