advent-of-code/app/one.hs

15 lines
415 B
Haskell

import Text.Read
f :: (Int,Int) -> Maybe Int -> (Int,Int)
f (max,current) (Just next) = (max,current+next)
f (currentMax,current) (Nothing) = (max currentMax current ,0)
result=fst $ foldl f (0,0) (map (readMaybe) $lines "1000\n2000\n3000\n\n4000\n1000\n\n1000")
compute input=fst $ foldl f (0,0) $ map (readMaybe) $lines input
main = do
content <- readFile "elves.txt"
putStrLn $ show $compute content