Maximum triangle path sum: Difference between revisions

Content added Content deleted
(+ Python solution)
(+ second Python entry)
Line 94: Line 94:
{{out}}
{{out}}
<pre>1320</pre>
<pre>1320</pre>

A more functional version, similar to the Haskell entry (same output):
<lang python>from itertools import imap

f = lambda x, y, z: x + max(y, z)
g = lambda xs, ys: list(imap(f, ys, xs, xs[1:]))
data = [map(int, row.split()) for row in open("triangle.txt")][::-1]
print reduce(g, data)[0]</lang>