Files
advent-of-code-2022/src/Day1.hs

39 lines
979 B
Haskell
Raw Normal View History

2022-12-01 15:57:27 +01:00
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)
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 =
2022-12-01 16:06:38 +01:00
calories . sumCalories . take 3 . sortElves . parseElfInput
2022-12-01 15:57:27 +01:00
where
sumCalories :: [Elf] -> Int
2022-12-01 16:06:38 +01:00
sumCalories = sum . map getCalories
2022-12-01 15:57:27 +01:00
findElfWithHighestCalorieCount :: T.Text -> Elf
2022-12-01 16:06:38 +01:00
findElfWithHighestCalorieCount = head . sortElves . parseElfInput