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