Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Golden Pyramid by zator55
def count_gold(pyramid):
pyramid = [list(t) for t in pyramid] # to list
for y in range(1, len(pyramid)):
for x in range(len(pyramid[y])):
up_right_room = 0 if x >= len(pyramid[y - 1]) else pyramid[y - 1][x]
up_left_room = 0 if x == 0 else pyramid[y - 1][x - 1]
pyramid[y][x] += max(up_right_room, up_left_room)
return max(pyramid[-1])
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