X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=advent04%2FMain.hs;h=783d9f5bb8e910f22b0760c7e6603a56ad5da9f6;hb=f961efa630553f9630649481bc6380ec70949720;hp=0e11075009b8c0f6bada7b8af9f288a297ec1a9a;hpb=78319b93c9cbce071c99eb5b7355ab7e76535031;p=advent-of-code-21.git diff --git a/advent04/Main.hs b/advent04/Main.hs index 0e11075..783d9f5 100644 --- a/advent04/Main.hs +++ b/advent04/Main.hs @@ -1,3 +1,5 @@ +-- Writeup at https://work.njae.me.uk/2021/12/04/advent-of-code-2021-day-4/ + import Data.Text () import qualified Data.Text.IO as TIO @@ -7,9 +9,12 @@ import Control.Applicative import Data.List type Square = [[Int]] -type BingoSquare = [[BingoNum]] + data BingoNum = BingoNum Int Bool deriving (Eq, Show) + +type BingoSquare = [[BingoNum]] + data BingoState = BingoState Int [BingoSquare] deriving (Eq, Show) @@ -52,7 +57,6 @@ pruningBingoStep (BingoState _ squares) caller = BingoState caller squares'' hasCompletedSquare :: BingoState -> Bool hasCompletedSquare (BingoState _n squares) = any completed squares - unmarkedSum :: BingoSquare -> Int unmarkedSum bingoSquare = sum [value bn | r <- bingoSquare, bn <- r, (not $ isCalled bn)]