Day 1 Part 2
This commit is contained in:
parent
34d5494402
commit
3afb01ca78
18
01/Main.idr
18
01/Main.idr
|
@ -2,18 +2,30 @@ import System.File.ReadWrite
|
|||
import Data.String
|
||||
import Data.List1
|
||||
|
||||
parseInput : String -> List1 (List Int)
|
||||
parseInput input =
|
||||
let inputLines = lines input
|
||||
grouped = split (== "") inputLines
|
||||
in map (map cast) grouped
|
||||
|
||||
part1 : String -> IO ()
|
||||
part1 input =
|
||||
let inputLines = lines input
|
||||
grouped = split (== "") inputLines
|
||||
parsed = map (map cast) grouped
|
||||
let parsed = parseInput input
|
||||
totals = map (foldr (+) 0) parsed
|
||||
in do printLn $ foldr max 0 totals
|
||||
|
||||
part2 : String -> IO ()
|
||||
part2 input =
|
||||
let parsed = parseInput input
|
||||
totals = map (foldr (+) 0) parsed
|
||||
sorted = reverse . sort . forget $ totals
|
||||
|
||||
main : IO ()
|
||||
main = do file <- readFile "input"
|
||||
case file of
|
||||
Right content =>
|
||||
do putStr "Part 1: "
|
||||
part1 content
|
||||
putStr "Part 2: "
|
||||
part2 content
|
||||
Left err => printLn err
|
||||
|
|
Loading…
Reference in New Issue