Advertisement
Guest User

Untitled

a guest
Oct 26th, 2015
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.32 KB | None | 0 0
  1. def josephus_survivor(n,k):
  2.     soldiers = [int(i) for i in range(1, n + 1)]
  3.     counter = -1
  4.     while len(soldiers) != 1:
  5.         counter += k
  6.         while counter >= len(soldiers):
  7.             counter = abs(len(soldiers) - counter)
  8.         soldiers.remove(soldiers[counter])
  9.         counter -= 1
  10.     return soldiers[0]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement