Maximum triangle path sum: Difference between revisions
Content added Content deleted
m (→{{header|Sidef}}: minor code simplifications) |
m (added whitespace before the TOC (table of contents), added a ;Task: (bold) header.) |
||
Line 1: | Line 1: | ||
{{task}} |
{{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: |
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> |
<pre> |
||
Line 5: | Line 6: | ||
94 48 |
94 48 |
||
95 30 96 |
95 30 96 |
||
77 71 26 67 |
77 71 26 67 |
||
</pre> |
|||
One of such walks is 55 - 94 - 30 - 26. |
One of such walks is 55 - 94 - 30 - 26. |
||
Line 13: | Line 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. |
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: |
|||
Find the maximum total in the triangle below: |
|||
<pre> |
<pre> |
||
55 |
55 |
||
Line 32: | Line 35: | ||
85 32 25 85 57 48 84 35 47 62 17 01 01 99 89 52 |
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 |
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 |
27 02 92 23 08 71 76 84 15 52 92 63 81 10 44 10 69 93 |
||
</pre> |
|||
Such numbers can be included in the solution code, or read from a "triangle.txt" file. |
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]. |
This task is derived from the [http://projecteuler.net/problem=18 Euler Problem #18]. |
||
<br><br> |
|||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
<lang ada>with Ada.Text_Io; use Ada.Text_Io; |
<lang ada>with Ada.Text_Io; use Ada.Text_Io; |