Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
One-Liner solution in Clear category for Golden Pyramid by Krischtopp
def count_gold(pyramid, pos=(0, 0)):
"""
On the pyramid we can only make a step down or down and to the right.
We return the maximum of our both steps plus the value we are standing on.
If we cannot make a step, because we are already at the foot of the pyramid, we just return the value we are standing on.
"""
return max(count_gold(pyramid, (pos[0] + 1, pos[1])), count_gold(pyramid, (pos[0] + 1, pos[1] + 1))) + pyramid[pos[0]][pos[1]] if pos[0] + 1 < len(pyramid) else pyramid[pos[0]][pos[1]]
Jan. 26, 2016