Advertisement
DiYane

Josephus Permutation

Oct 7th, 2023
820
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.38 KB | None | 0 0
  1. people = input().split(' ')
  2. kills = int(input())
  3. executed = []
  4. counter = 0
  5. current_index = 0
  6.  
  7. while len(people) > 0:
  8.     counter += 1
  9.  
  10.     if counter % kills == 0:
  11.         executed.append(people.pop(current_index))
  12.     else:
  13.         current_index += 1
  14.  
  15.     if current_index >= len(people):
  16.         current_index = 0
  17.  
  18. print(str(executed).replace(' ', '').replace('\'', ''))
Tags: python
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement