Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Golden Pyramid by e.volgon
def count_gold(pyramid):
"""
1) Inverted Triangle:
Example 5 - 6 - 4 - 5 - 6 - 4 - 3
2 - 2 - 2 - 2 - 2 - 2
3 - 1 - 3 - 1 - 3
3 - 1 - 5 - 4
3 - 3 - 1
2 - 3
1
2) For item in second line: take a large item from line above, and add to item from current line.
Example: 5 - 6 - 4 - 5 - 6 - 4 - 3 ------------------------
/ \ / / \ \ >>>>>>>>>
2 - 2 - 2 - 2 - 2 - 2 8 - 8 - 7 - 8 - 8 - 6
....... .........
3) With same logic go from line to line until bottom of the pyramid
"""
cp_pyr = [list(r[:]) for r in pyramid] # copy pyramid
for row in range(len(cp_pyr)-2, -1, -1): # move reversal from 2nd line
for col in range(row+1):
cp_pyr[row][col] += max(cp_pyr[row+1][col], cp_pyr[row+1][col+1]) # add large item from line above
return cp_pyr[0][0]
Aug. 11, 2015
Comments: