advent-of-code/app/one2.hs

13 lines
369 B
Haskell
Raw Normal View History

2022-12-17 14:50:06 +01:00
import Text.Read
import Data.List
f :: ([Int],Int) -> Maybe Int -> ([Int],Int)
f (max,current) (Just next) = (max,current+next)
f (currentMax,current) (Nothing) = (take 3 $ reverse $ sort (current:currentMax) ,0)
compute input=sum $fst $ foldl f ([0],0) $ map (readMaybe) $lines input
main = do
content <- readFile "elves.txt"
putStrLn $ show $compute content