Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2021
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. from collections import deque
  2. import sys
  3.  
  4.  
  5. def best_list_pureness(*avg):
  6.  
  7. collection = deque(avg[0])
  8. rotations = int(avg[1])
  9.  
  10. best_pureness = -sys.maxsize
  11. best_rotation = 0
  12.  
  13. for rotation in range(rotations):
  14.  
  15. list_pureness = 0
  16. for idx, val in enumerate(collection):
  17. list_pureness += idx * val
  18. if list_pureness > best_pureness:
  19. best_pureness = list_pureness
  20. best_rotation = rotation
  21.  
  22. el = collection.pop()
  23. collection.appendleft(el)
  24.  
  25. return f"Best pureness {best_pureness} after {best_rotation} rotations"
  26.  
  27.  
  28.  
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement