License | MIT |
---|---|
Maintainer | @tylerjl |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Solutions to the 2021 day 04 set of problems for adventofcode.com.
Synopsis
- newtype Bingo a = Bingo a
- data Card
- type ColSet = Set (Set (Sum Int))
- type RowSet = Set (Set (Sum Int))
- type Square = Maybe (Sum Int)
- part4A :: Text -> Int
- part4ASet :: Text -> Int
- part4B :: Text -> Int
- part4BSet :: Text -> Int
- intoSet :: Card -> Card
- solve4 :: ([(Int, Bingo Card)] -> (Int, Bingo Card)) -> [Int] -> [Bingo Card] -> Int
- tally :: (Int, Bingo Card) -> Int
- sumCard :: Card -> Int
- iterateMap :: [Int] -> [Bingo Card] -> [(Int, Bingo Card)]
- mark :: ([Bingo Card], [Bingo Card]) -> Int -> [Bingo Card] -> ([Bingo Card], [Bingo Card])
- markRows :: Int -> Bingo Card -> Bingo Card
- gameEnd :: Bingo Card -> Bool
- bingoParser :: Text -> Either String ([Int], [Bingo Card])
Documentation
Fancy data type to represent _game_ state, not just a card
Bingo a |
Represents a game board state
Transform a bingo game from multidimensional-array based to a set-based game.
solve4 :: ([(Int, Bingo Card)] -> (Int, Bingo Card)) -> [Int] -> [Bingo Card] -> Int #
Fortunately both A and B are just asking slightly different questions, so we have a higher-order function to determine how to pull the matching value from our resultant list.
tally :: (Int, Bingo Card) -> Int #
Problem-defined method of scoring a card. The "in-progress" scoring isn't actually ever used. Probably a bug.
iterateMap :: [Int] -> [Bingo Card] -> [(Int, Bingo Card)] #
Our main recursive loop to walk through the "called" numbers. We return a list solely of elements that meet the "ended" predicate.
mark :: ([Bingo Card], [Bingo Card]) -> Int -> [Bingo Card] -> ([Bingo Card], [Bingo Card]) #
Accept a list of `Bingo Card`s and update each with the called number.