1
0
Fork 0
advent-of-code/2022/src/Aoc/Day1.hs

25 lines
596 B
Haskell
Raw Normal View History

2022-12-01 10:07:52 -05:00
{-# LANGUAGE OverloadedStrings #-}
module Aoc.Day1 (solve) where
import Data.Ord
import Data.List (sortBy)
import Data.Text (pack, splitOn, unpack)
parseInput :: String -> [[Integer]]
parseInput = (map (map read . words . unpack)) . splitOn "\n\n" . pack
inputSums :: String -> [Integer]
inputSums = map sum . parseInput
part1 :: String -> Integer
part1 = maximum . inputSums
part2 :: String -> Integer
part2 = sum . take 3 . sortDesc . inputSums
where
sortDesc = sortBy (comparing Down)
solve :: Integer -> String -> Integer
solve 1 input = part1 input
solve 2 input = part2 input