Guest User

Untitled

a guest
Jun 1st, 2016
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.04 KB | None | 0 0
  1. def count_gold(pyramid):
  2.     pyramid = [[i for i in x] for x in pyramid]
  3.     while len(pyramid) != 1:
  4.         for i in range(len(pyramid[len(pyramid) - 2])):
  5.             pyramid[len(pyramid) - 2][i] = pyramid[len(pyramid) - 2][i] + max(pyramid[len(pyramid) - 1][i], pyramid[len(pyramid) - 1][i + 1])
  6.         pyramid.remove(pyramid[len(pyramid) - 1])
  7.     return pyramid[0][0]
  8.  
  9.  
  10. if __name__ == '__main__':
  11.     #These "asserts" using only for self-checking and not necessary for auto-testing
  12.     assert count_gold((
  13.         (1,),
  14.         (2, 3),
  15.         (3, 3, 1),
  16.         (3, 1, 5, 4),
  17.         (3, 1, 3, 1, 3),
  18.         (2, 2, 2, 2, 2, 2),
  19.         (5, 6, 4, 5, 6, 4, 3)
  20.     )) == 23, "First example"
  21.     assert count_gold((
  22.         (1,),
  23.         (2, 1),
  24.         (1, 2, 1),
  25.         (1, 2, 1, 1),
  26.         (1, 2, 1, 1, 1),
  27.         (1, 2, 1, 1, 1, 1),
  28.         (1, 2, 1, 1, 1, 1, 9)
  29.     )) == 15, "Second example"
  30.     assert count_gold((
  31.         (9,),
  32.         (2, 2),
  33.         (3, 3, 3),
  34.         (4, 4, 4, 4)
  35.     )) == 18, "Third example"
Advertisement
Add Comment
Please, Sign In to add comment