Advertisement
dimanou_04

03_list_pureness

Oct 19th, 2022
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. from collections import deque
  2.  
  3.  
  4. def best_list_pureness(*args):
  5.     pureness_elements = {}
  6.     rotations = 0
  7.     numbers = deque([x for x in args[0]])
  8.  
  9.     for _ in range(args[-1]):
  10.         total_sum = 0
  11.         for idx, num in enumerate(numbers):
  12.             total_sum += idx * num
  13.  
  14.         if total_sum not in pureness_elements:
  15.             pureness_elements[total_sum] = rotations
  16.  
  17.         rotations += 1
  18.         numbers.appendleft(numbers.pop())
  19.  
  20.     return f'Best pureness {max(pureness_elements)} after {pureness_elements[max(pureness_elements)]} rotations'
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement