Solve day 6 part 1
This commit is contained in:
parent
cb86dad006
commit
5539a4bd05
@ -56,7 +56,7 @@ import Data.Char
|
||||
import Data.Foldable hiding (foldl1, foldr1, maximum, maximumBy, minimum, minimumBy)
|
||||
import Data.Foldable1
|
||||
import Data.Functor
|
||||
import Data.List (sortOn)
|
||||
import Data.List (sortOn, transpose)
|
||||
import Data.List.Extra (dropEnd, enumerate)
|
||||
import Data.List.NonEmpty (NonEmpty ((:|)), nonEmpty, some1)
|
||||
import Data.Maybe
|
||||
|
||||
@ -2,14 +2,32 @@ module Puzzles.Day6 (puzzle) where
|
||||
|
||||
import Pre
|
||||
|
||||
import Data.Text.Lazy qualified as TL
|
||||
|
||||
puzzle :: Puzzle
|
||||
puzzle =
|
||||
Puzzle
|
||||
{ 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 =
|
||||
[ \() ->
|
||||
"TODO"
|
||||
[ TL.show
|
||||
. sum
|
||||
. uncurry (zipWith \op -> foldl' (apply op) (unit op))
|
||||
]
|
||||
, 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
1
outputs/real/6/1
Normal file
@ -0,0 +1 @@
|
||||
8108520669952
|
||||
Loading…
x
Reference in New Issue
Block a user