Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Golden Pyramid by internom
def count_gold(pyramid):
# Convert to tuple to list ()
pyramid = [list(row) for row in pyramid]
# Dynamic programming
for i, row in enumerate(pyramid):
if i == 0:
continue
for j, val in enumerate(row):
if j == 0:
pyramid[i][j] = pyramid[i-1][j] + val
continue
if j == len(row)-1:
pyramid[i][j] = pyramid[i-1][j-1] + val
continue
pyramid[i][j] = max(pyramid[i-1][j-1], pyramid[i-1][j]) + val
return max(pyramid[-1])
Dec. 16, 2015