40 lines
1002 B
Haskell
40 lines
1002 B
Haskell
|
|
module Day1 (
|
||
|
|
day1,
|
||
|
|
findElfWithHighestCalorieCount,
|
||
|
|
findCaloriesOfTop3Elves
|
||
|
|
) where
|
||
|
|
|
||
|
|
import qualified Data.Text as T
|
||
|
|
import Day1.Internal
|
||
|
|
|
||
|
|
day1 :: IO ()
|
||
|
|
day1 = do
|
||
|
|
putStrLn "Day1"
|
||
|
|
calorieCount <- day1_1
|
||
|
|
putStrLn ("Highest calorie count = " ++ calorieCount)
|
||
|
|
caloriesOfTop3Elves <- day1_2
|
||
|
|
putStrLn ("Calories of top 3 elves = " ++ caloriesOfTop3Elves)
|
||
|
|
putStrLn "-----------"
|
||
|
|
|
||
|
|
|
||
|
|
day1_1 :: IO String
|
||
|
|
day1_1 = do
|
||
|
|
input <- readFile "ressources/day01-input"
|
||
|
|
return (show $ findElfWithHighestCalorieCount $ T.pack input)
|
||
|
|
|
||
|
|
day1_2 :: IO String
|
||
|
|
day1_2 = do
|
||
|
|
input <- readFile "ressources/day01-input"
|
||
|
|
return (show $ findCaloriesOfTop3Elves $ T.pack input)
|
||
|
|
|
||
|
|
|
||
|
|
findCaloriesOfTop3Elves :: T.Text -> CalorieCount
|
||
|
|
findCaloriesOfTop3Elves =
|
||
|
|
calories . sumCalories . take 3 . sortElves . elfToCalories
|
||
|
|
where
|
||
|
|
sumCalories :: [Elf] -> Int
|
||
|
|
sumCalories = sum . map caloriesOf
|
||
|
|
|
||
|
|
findElfWithHighestCalorieCount :: T.Text -> Elf
|
||
|
|
findElfWithHighestCalorieCount = head .sortElves . elfToCalories
|