Solve day 6 part 1

This commit is contained in:
George Thomas 2025-12-08 15:52:20 +00:00
parent cb86dad006
commit 5539a4bd05
3 changed files with 23 additions and 4 deletions

View File

@ -56,7 +56,7 @@ import Data.Char
import Data.Foldable hiding (foldl1, foldr1, maximum, maximumBy, minimum, minimumBy) import Data.Foldable hiding (foldl1, foldr1, maximum, maximumBy, minimum, minimumBy)
import Data.Foldable1 import Data.Foldable1
import Data.Functor import Data.Functor
import Data.List (sortOn) import Data.List (sortOn, transpose)
import Data.List.Extra (dropEnd, enumerate) import Data.List.Extra (dropEnd, enumerate)
import Data.List.NonEmpty (NonEmpty ((:|)), nonEmpty, some1) import Data.List.NonEmpty (NonEmpty ((:|)), nonEmpty, some1)
import Data.Maybe import Data.Maybe

View File

@ -2,14 +2,32 @@ module Puzzles.Day6 (puzzle) where
import Pre import Pre
import Data.Text.Lazy qualified as TL
puzzle :: Puzzle puzzle :: Puzzle
puzzle = puzzle =
Puzzle Puzzle
{ number = 6 { number = 6
, parser = pure () , parser = do
ints <- (hspace *> (decimal `sepBy1` hspace1)) `sepEndBy1` newline
ops <- ((single '*' $> Multiply) <|> (single '+' $> Add)) `sepEndBy` hspace1
void newline
pure (ops, transpose ints)
, parts = , parts =
[ \() -> [ TL.show
"TODO" . sum
. uncurry (zipWith \op -> foldl' (apply op) (unit op))
] ]
, extraTests = mempty , extraTests = mempty
} }
data Op = Add | Multiply
deriving (Eq, Ord, Show, Enum, Bounded)
apply :: Op -> Int -> Int -> Int
apply = \case
Add -> (+)
Multiply -> (*)
unit :: Op -> Int
unit = \case
Add -> 0
Multiply -> 1

1
outputs/real/6/1 Normal file
View File

@ -0,0 +1 @@
8108520669952