1
0
Fork 0
advent-of-code/2022/app/Main.hs
2022-12-01 09:26:39 -05:00

33 lines
768 B
Haskell

{-# LANGUAGE OverloadedStrings #-}
module Main (main) where
import System.Environment (getArgs)
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)
main :: IO ()
main = do
args <- getArgs
contents <- getContents
let f = case args of ("1":_) -> part1
("2":_) -> part2
_ -> error "unknown part"
putStrLn $ show $ f contents