Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Golden Pyramid by przemyslaw.jan.pietrzak
def getGold(pyramid, path):
gold=pyramid[0][0]
idx=0
for leap in range(1,len(pyramid)):
idx+=int(path[leap-1])
gold+=pyramid[leap][idx]
return gold
def count_gold(pyramid):
levels=len(pyramid)
nPaths=2**(levels-1)
print("Pyramid[" + str(nPaths) + "paths]: " + str(pyramid))
maxGold=0
for x in range(0,nPaths):
path=str(bin(x)[2:]).zfill(levels-1)
gold=getGold(pyramid,path)
maxGold=max(maxGold,gold)
print("Max Path: " + path + " - Max Gold: " + str(maxGold))
return maxGold
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert count_gold((
(1,),
(2, 3),
(3, 3, 1),
(3, 1, 5, 4),
(3, 1, 3, 1, 3),
(2, 2, 2, 2, 2, 2),
(5, 6, 4, 5, 6, 4, 3)
)) == 23, "First example"
assert count_gold((
(1,),
(2, 1),
(1, 2, 1),
(1, 2, 1, 1),
(1, 2, 1, 1, 1),
(1, 2, 1, 1, 1, 1),
(1, 2, 1, 1, 1, 1, 9)
)) == 15, "Second example"
assert count_gold((
(9,),
(2, 2),
(3, 3, 3),
(4, 4, 4, 4)
)) == 18, "Third example"
Jan. 28, 2016