Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Golden Pyramid by Mahoter
def count_gold(pyramid):
pyramid = list(pyramid)
a = 0
b = 2
suma = pyramid.pop()
pyramid.reverse()
b = 2
while a < len(pyramid):
c = 0
d = 0
temp = list(suma)
suma = []
x = 0
while x < len(temp):
d += 1
suma += [pyramid[a][c] + temp[x]]
x += 1
if d == b and c < len(pyramid[a]) - 1:
x -= int(b/2)
d = 0
c += 1
b = b*2
a+= 1
"""
Return max possible sum in a path from top to bottom
"""
#replace this for solution
return max(suma)
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. 24, 2016