21 lines
522 B
Haskell
21 lines
522 B
Haskell
easyTree = [[3], [7,4], [2,4,6], [8,5,9,3]]
|
|
|
|
parseToLists :: String -> [[Integer]]
|
|
parseToLists = map (map read . words) . lines
|
|
|
|
maxPairs :: Ord a => [a] -> [a]
|
|
maxPairs [x] = [x]
|
|
maxPairs xs = zipWith max (init xs) (tail xs)
|
|
|
|
nextRow :: Num a => Ord a => [a] -> [a] -> [a]
|
|
nextRow ls hs = zipWith (+) (maxPairs ls) hs
|
|
|
|
solveTree :: Num a => Ord a => [[a]] -> [a]
|
|
solveTree xs = foldl nextRow y ys
|
|
where (y:ys) = reverse xs
|
|
|
|
main = do
|
|
s <- readFile "67.txt"
|
|
let l = parseToLists s
|
|
putStrLn . show . solveTree $ l
|