Maximum triangle path sum: Difference between revisions

Content added Content deleted
m (→‎{{header|Sidef}}: modified code to work with the latest version of Sidef)
Line 617: Line 617:
Explanation:
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.
First, we pad all short rows with trailing 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.
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.