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