Anonymous user
Maximum triangle path sum: Difference between revisions
+ second Python entry
(+ Python solution) |
(+ second Python entry) |
||
Line 94:
{{out}}
<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>
|