This commit is contained in:
Martin Potier 2022-12-09 22:32:19 +02:00
parent 539b0e6140
commit b252ad75ed
No known key found for this signature in database
GPG key ID: D4DD957DBA4AD89E
3 changed files with 2262 additions and 1 deletions

View file

@ -1,2 +1,8 @@
import AoC.Day1 as Day1
main :: IO () main :: IO ()
main = putStrLn "Hello World!" main = do
putStrLn "Hello World!"
input <- readFile "./input/day1.txt"
putStrLn $ show $ Day1.solveA input
putStrLn $ show $ Day1.solveB input

2248
input/day1.txt Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,3 +1,10 @@
module AoC.Day1 where module AoC.Day1 where
import Data.List (groupBy,null,sort)
parseInput :: String -> [[Int]]
parseInput = map (map read) . map tail . groupBy (\l r -> (not $ null r)) . lines
solveA = maximum . map sum . parseInput
solveB = sum . take 3 . reverse . sort . map sum . parseInput