Jump to content

Maximum triangle path sum: Difference between revisions

m
added whitespace before the TOC (table of contents), added a ;Task: (bold) header.
m (→‎{{header|Sidef}}: minor code simplifications)
m (added whitespace before the TOC (table of contents), added a ;Task: (bold) header.)
Line 1:
{{task}}
 
Starting from the top of a pyramid of numbers like this, you can walk down going one step on the right or on the left, until you reach the bottom row:
<pre>
Line 5 ⟶ 6:
94 48
95 30 96
77 71 26 67</pre>
</pre>
 
One of such walks is 55 - 94 - 30 - 26.
Line 13 ⟶ 15:
Your problem is to find the maximum total among all possible paths from the top to the bottom row of the triangle. In the little example above it's 321.
 
;Task:
'''Task:''' findFind the maximum total in the triangle below:
<pre>
55
Line 32 ⟶ 35:
85 32 25 85 57 48 84 35 47 62 17 01 01 99 89 52
06 71 28 75 94 48 37 10 23 51 06 48 53 18 74 98 15
27 02 92 23 08 71 76 84 15 52 92 63 81 10 44 10 69 93</pre>
</pre>
 
Such numbers can be included in the solution code, or read from a "triangle.txt" file.
 
This task is derived from the [http://projecteuler.net/problem=18 Euler Problem #18].
<br><br>
 
=={{header|Ada}}==
<lang ada>with Ada.Text_Io; use Ada.Text_Io;
Cookies help us deliver our services. By using our services, you agree to our use of cookies.