Skip to content

Instantly share code, notes, and snippets.

@slapec
Created January 4, 2021 19:07
Show Gist options
  • Save slapec/c450b27494f95930bb46784f848fe67f to your computer and use it in GitHub Desktop.
Save slapec/c450b27494f95930bb46784f848fe67f to your computer and use it in GitHub Desktop.
import collections
def josephus_survivor(n, k):
population = collections.deque(range(1, n + 1))
retval = None
while population:
population.rotate(1 - k)
retval = population.popleft()
return retval
print(josephus_survivor(4000, 50))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment