Maximum triangle path sum: Difference between revisions

Content added Content deleted
(+ D entry)
(+ Haskell solution)
Line 45: Line 45:
.writeln;
.writeln;
}</lang>
}</lang>
{{out}}
<pre>1320</pre>

=={{header|Haskell}}==
This solution assumes the triangle is in a "triangle.txt" file.

<lang haskell>parse = map (map read . words) . lines
f x y z = x + max y z
g xs ys = zipWith3 f xs ys $ tail ys
solve = head . foldr1 g
main = readFile "triangle.txt" >>= print . solve . parse</lang>
{{out}}
{{out}}
<pre>1320</pre>
<pre>1320</pre>