Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Straightforward solution in Clear category for Golden Pyramid by siebenschlaefer
def count_gold(pyramid):
"""Return the maximal sum of a path in 'pyramid'."""
max_values = list(pyramid[0])
for row in pyramid[1:]:
max_values = [0] + max_values + [0]
max_values = [
value + max(max_values[i], max_values[i + 1])
for i, value in enumerate(row)]
return max(max_values)
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"
Aug. 1, 2015