Skip to content

Instantly share code, notes, and snippets.

@iximeow
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save iximeow/0c716d5da9b060a378ed to your computer and use it in GitHub Desktop.

Select an option

Save iximeow/0c716d5da9b060a378ed to your computer and use it in GitHub Desktop.
import Data.List.Split
euler :: [[Int]] -> Int
euler a = head (head (collapse a))
collapse :: [[Int]] -> [[Int]]
collapse a = if length a > 1 then
collapse ((init (init a)) ++ [euler18max (last a) (last (init a))]) else a
--We ALWAYS want b to be one larger than a
----Always.
euler18max :: [Int] -> [Int] -> [Int]
euler18max a b = zipWith max (zipWith (+) b (init a) ) (zipWith (+) b (tail a) )
rd :: [String] -> [Int]
rd = map read
main :: IO ()
main = do
contents <- readFile "C:/haskell/project67/triangle.txt"
let f = map (splitOn " ") (splitOn "\n" contents)
--print f
print (euler (map (rd) f))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment