Created
July 22, 2012 19:40
-
-
Save jzempel/3160842 to your computer and use it in GitHub Desktop.
Duck, Duck, Survivor
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
def survivor(count): | |
if count >= 2: | |
survivors = range(1, count + 1) | |
start = 1 | |
last = survivors[-1] | |
while len(survivors) > 1: | |
survivors = survivors[start::2] | |
start = 1 if last == survivors[-1] else 0 | |
last = survivors[-1] | |
ret_val = survivors[0] | |
else: | |
ret_val = count | |
return ret_val |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment