Advertisement
Kamend1

List Pureness = test 1 wrong

Feb 11th, 2024
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. from collections import deque
  2.  
  3.  
  4. def best_list_pureness(user_list, num):
  5.     rotations = 0
  6.     best_pureness = 0
  7.     best_turn = 0
  8.     user_list = deque(user_list)
  9.  
  10.     for _ in range(num):
  11.         current_pureness = 0
  12.         user_list.rotate()
  13.         rotations += 1
  14.         if rotations == len(user_list):
  15.             rotations = 0
  16.  
  17.         for idx in range(len(user_list)):
  18.             current_pureness += user_list[idx] * idx
  19.  
  20.         if current_pureness > best_pureness:
  21.             best_pureness = current_pureness
  22.             best_turn = rotations
  23.  
  24.     if best_pureness:
  25.         return f"Best pureness {best_pureness} after {best_turn} rotations"
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement