adventofcode-0.1.0.0: Haskell solutions to adventofcode
LicenseMIT
Maintainer@tylerjl
Safe HaskellSafe-Inferred
LanguageHaskell2010

Y2021.D04

Description

Solutions to the 2021 day 04 set of problems for adventofcode.com.

Synopsis

Documentation

newtype Bingo a #

Fancy data type to represent _game_ state, not just a card

Constructors

Bingo a 

Instances

Instances details
Functor Bingo #

I'm not sure if a derive would get this right

Instance details

Defined in Y2021.D04

Methods

fmap :: (a -> b) -> Bingo a -> Bingo b Source #

(<$) :: a -> Bingo b -> Bingo a Source #

Show a => Show (Bingo a) # 
Instance details

Defined in Y2021.D04

data Card #

Represents a game board state

Constructors

CardArr [[Square]] 
CardSet RowSet ColSet 

Instances

Instances details
Show Card # 
Instance details

Defined in Y2021.D04

type ColSet = Set (Set (Sum Int)) #

Alternative game board representation

type RowSet = Set (Set (Sum Int)) #

type Square = Maybe (Sum Int) #

Small wrapper over how to record marked/unmarked squares

part4A :: Text -> Int #

Solve part A

part4ASet :: Text -> Int #

Solve part A - with sets!

part4B :: Text -> Int #

Solve part B

part4BSet :: Text -> Int #

Solve part B - with sets!

intoSet :: Card -> Card #

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.

sumCard :: Card -> Int #

Yank out the total values for a card.

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.

markRows :: Int -> Bingo Card -> Bingo Card #

Update a Card - we make the determination to "end" a game here, so as soon as its "won" the type swaps over to the ended value.

gameEnd :: Bingo Card -> Bool #

Important function to determine if a card is a winning card.

bingoParser :: Text -> Either String ([Int], [Bingo Card]) #

This is a sort of hairy, but all-in-one, parser for the problem set input. 5 is a magic number for board size.