Jump to content

Maximum triangle path sum: Difference between revisions

m
m (Added Sidef language)
Line 407:
<lang j> maxSum padTri freads 'triangle.txt'
1320</lang>
 
Explanation:
 
First, we pad all short rows with tailing zeros so that all rows are the same length. This eliminates some ambiguity and simplifies the expression of both the data and the code.
 
Second, starting with the last row, for each pair of numbers we find the largest of the two (resulting in a list slightly shorter than before, so of course we pad it with a trailing zero) and add that row to the previous row. After repeating this through all the rows, the first value of the resulting row is the maximum we were looking for.
 
=={{header|Java}}==
6,962

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.