Done day 21
[advent-of-code-22.git] / advent01 / Main.hs
1 -- Writeup at https://work.njae.me.uk/2022/12/01/advent-of-code-2022-day-1/
2
3 import AoC
4 import Data.List
5 import Data.List.Split
6 import Data.Ord
7
8 main :: IO ()
9 main =
10 do dataFileName <- getDataFileName
11 numStrs <- readFile dataFileName
12 let calories = fmap (fmap (read @Int)) $ splitWhen null $ lines numStrs
13 print $ part1 calories
14 print $ part2 calories
15
16 part1 :: [[Int]] -> Int
17 part1 = maximum . fmap sum
18
19 part2 :: [[Int]] -> Int
20 -- part2 = sum . take 3 . reverse . sort . fmap sum
21 part2 = sum . take 3 . sortOn Down . fmap sum
22