Created
January 4, 2021 19:07
-
-
Save slapec/c450b27494f95930bb46784f848fe67f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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