Jump to content

Maximum triangle path sum: Difference between revisions

no edit summary
(Add Nimrod)
No edit summary
Line 318:
</pre>
 
=={{header|Nimrod}}==
{{trans|Python}}
<lang nimrod>import strutils, sequtilsfuture
 
proc solve(tri): int =
var tri = tri
while tri.len > 1:
let t0 = tri.pop()
for i, t in t1tri[tri.high]: tri[tri.high].add[i] = max(t0[i], t0[i+1]) + t
let t1 = tri.pop()
tri.add newSeq[int0][0]()
for i, t in t1: tri[tri.high].add max(t0[i], t0[i+1]) + t
return tri[0][0]
 
const data = """ 55
55
94 48
95 30 96
Line 350 ⟶ 349:
27 02 92 23 08 71 76 84 15 52 92 63 81 10 44 10 69 93"""
 
forecho row insolve data.splitLines.map()(x: s.addstring) => rowx.split().map( parseInt)</lang>
var s = newSeq[seq[int]]()
for row in data.splitLines(): s.add row.split().map(parseInt)
echo solve(s)</lang>
Output:
<pre>1320</pre>
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.