day1
This commit is contained in:
39
src/Day1.hs
Normal file
39
src/Day1.hs
Normal file
@@ -0,0 +1,39 @@
|
||||
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
|
||||
Reference in New Issue
Block a user