Reduce allocations and refactoring
This commit is contained in:
parent
7c0439ea30
commit
5442bbfd52
@ -22,6 +22,7 @@ function Problem18()
|
||||
That is, 3 + 7 + 4 + 9 = 23.
|
||||
|
||||
Find the maximum total from top to bottom of the triangle above =#
|
||||
|
||||
triangle = [ # Mutable
|
||||
[75],
|
||||
[95, 64],
|
||||
@ -39,10 +40,10 @@ function Problem18()
|
||||
[63, 66, 4, 68, 89, 53, 67, 30, 73, 16, 69, 87, 40, 31],
|
||||
[4, 62, 98, 27, 23, 9, 70, 98, 73, 93, 38, 53, 60, 4, 23],
|
||||
]
|
||||
len_triangle = length(triangle)
|
||||
|
||||
for i in len_triangle - 1:-1:1
|
||||
for j in 1:length(triangle[i])
|
||||
len_triangle = length(triangle)
|
||||
for i = len_triangle-1:-1:1
|
||||
for j = 1:length(triangle[i])
|
||||
triangle[i][j] += max(triangle[i+1][j], triangle[i+1][j+1])
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user