2022/01/Main.idr

32 lines
804 B
Idris
Raw Normal View History

2022-12-01 10:57:04 -05:00
import System.File.ReadWrite
import Data.String
import Data.List1
2022-12-01 11:06:04 -05:00
parseInput : String -> List1 (List Int)
parseInput input =
let inputLines = lines input
grouped = split (== "") inputLines
in map (map cast) grouped
2022-12-01 10:57:04 -05:00
part1 : String -> IO ()
part1 input =
2022-12-01 11:06:04 -05:00
let parsed = parseInput input
2022-12-01 10:57:04 -05:00
totals = map (foldr (+) 0) parsed
in do printLn $ foldr max 0 totals
2022-12-01 11:06:04 -05:00
part2 : String -> IO ()
part2 input =
let parsed = parseInput input
totals = map (foldr (+) 0) parsed
sorted = reverse . sort . forget $ totals
2022-12-01 10:57:04 -05:00
main : IO ()
main = do file <- readFile "input"
case file of
Right content =>
do putStr "Part 1: "
part1 content
2022-12-01 11:06:04 -05:00
putStr "Part 2: "
part2 content
2022-12-01 10:57:04 -05:00
Left err => printLn err