Created
December 9, 2013 19:15
-
-
Save mdunsmuir/7879047 to your computer and use it in GitHub Desktop.
Haskell I/O sample program (Euler 18)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System.Environment(getArgs) | |
main = do args <- getArgs | |
if length args > 0 | |
then do inpstr <- readFile $ head args | |
putStrLn $ show (maxPathSum (parseData inpstr)) | |
else putStrLn "I need a filename with triangle data!" | |
parseData s = map (\s -> map read (words s)) $ lines s | |
maxPathSum list = | |
let addListsFold upper lower = zipWith (+) upper $ maxList lower | |
where | |
maxList (x:[]) = [] | |
maxList (x:y:xs) = (max x y) : (maxList $ y:xs) | |
in head $ foldr1 addListsFold list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment