# Untitled

Jun 25th, 2021
734
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. def best_list_pureness(*args):
2.     def calculate_p(p_lst):
3.         p = 0
4.         for idx in range(len(p_lst)):
5.             p += p_lst[idx] * idx
6.         return p
7.
8.     lst = args[0]
9.     k = args[-1]
10.     best_rotations = 0
11.     best_pureness = 0
12.     best_pureness = calculate_p(lst)
13.     for i in range(k):
14.         lst.insert(0, lst.pop())
15.         current_pureness = calculate_p(lst)
16.         if current_pureness > best_pureness:
17.             best_pureness = current_pureness
18.             best_rotations = i + 1
19.
20.     return f"Best pureness {best_pureness} after {best_rotations } rotations"
21.
22.
23. test = ([4, 3, 2, 6], 4)
24. result = best_list_pureness(*test)
25. print(result)
26.
27. test = ([7, 9, 2, 5, 3, 4], 3)
28. result = best_list_pureness(*test)
29. print(result)
30.
31. test = ([1, 2, 3, 4, 5], 10)
32. result = best_list_pureness(*test)
33. print(result)
RAW Paste Data