Advertisement
viligen

list_pureness

Feb 4th, 2022
648
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. from collections import deque
  2.  
  3.  
  4. def best_list_pureness(any_list, rotate_count):
  5.     best_pureness = 0
  6.     best_rotation = 0
  7.     rotation = 0
  8.     any_list = deque(any_list)
  9.     while rotation <= rotate_count:
  10.         current_pureness = sum([idx * value for idx, value in enumerate(any_list)])
  11.         if current_pureness > best_pureness:
  12.             best_pureness = current_pureness
  13.             best_rotation = rotation
  14.         rotation += 1
  15.         any_list.rotate(1)
  16.     return f'Best pureness {best_pureness} after {best_rotation} rotations'
  17.  
  18.  
  19. test = ([4, 3, 2, 6], 4)
  20. result = best_list_pureness(*test)
  21. print(result)
  22. test = ([7, 9, 2, 5, 3, 4], 3)
  23. result = best_list_pureness(*test)
  24. print(result)
  25. test = ([1, 2, 3, 4, 5], 10)
  26. result = best_list_pureness(*test)
  27. print(result)
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement