simeonshopov

Josephus Permutation

Dec 5th, 2019
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.27 KB | None | 0 0
  1. victums = [int(x) for x in input().split()]
  2. k = int(input())
  3. output = []
  4.  
  5. idx = k - 1
  6.  
  7. while len(victums) > 1:
  8.     output.append(victums.pop(idx))
  9.     idx = (idx + k - 1) % len(victums)
  10. else:
  11.     output.append(victums[0])
  12.  
  13. print(str(output).replace(' ', ''))
Advertisement
Add Comment
Please, Sign In to add comment