Advertisement
Kamend1

List Pureness = Only Test 1 right

Feb 11th, 2024
63
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. from math import inf
  3.  
  4. def best_list_pureness(user_list, num):
  5.     user_list = deque(user_list)
  6.     best_pureness = sum(value * idx for idx, value in enumerate(user_list))
  7.     best_turn = 0
  8.  
  9.     for rotation in range(1, num):
  10.         current_pureness = sum(value * idx for idx, value in enumerate(user_list))
  11.  
  12.         if current_pureness > best_pureness:
  13.             best_pureness = current_pureness
  14.             best_turn = rotation
  15.  
  16.         user_list.rotate()
  17.  
  18.     return f"Best pureness {best_pureness} after {best_turn} rotations"
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement