Maximum triangle path sum: Difference between revisions

m
m (→‎{{header|Factor}}: Use v+ instead of [ + ] 2map)
Line 703:
=={{header|Elena}}==
{{trans|C#}}
ELENA 3.4.x :
<lang elena>import system'routines.;
import extensions.;
import extensions'math.;
literalstring input = "55
94 48
95 30 96
Line 725:
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".;
public program()
{
[
var list := IntMatrix new IntMatrix(18,19).;
int i := 0.;
int j := 0.;
input .split(forwards'forward newLine); .forEach(:(string line)<literal>
[{
j := 0.;
line .trim; ().split(" "); .forEach(:(string num)<literal>
[{
list[i][j] := num toInt.toInt();
j += 1
].};
i += 1.
].};
16for(int i to:= 16, i >= 0, do(:i-=1)<int>
[{
0for(int j till:= 0, j < 18, do(:j += 1)<int>
[{
list[i][j] := mathControl .max(list[i][j] + list[i+1][j], list[i][j] + list[i+1][j+1])
]}
].};
console .printLine("Maximum total: ", list[0][0])
]}</lang>
{{out}}
<pre>
Anonymous user