Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def count_gold(pyramid):
- pyramid = [[i for i in x] for x in pyramid]
- while len(pyramid) != 1:
- for i in range(len(pyramid[len(pyramid) - 2])):
- pyramid[len(pyramid) - 2][i] = pyramid[len(pyramid) - 2][i] + max(pyramid[len(pyramid) - 1][i], pyramid[len(pyramid) - 1][i + 1])
- pyramid.remove(pyramid[len(pyramid) - 1])
- return pyramid[0][0]
- 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"
Advertisement
Add Comment
Please, Sign In to add comment