Skip to content

Instantly share code, notes, and snippets.

@jzempel
Created July 22, 2012 19:40
Show Gist options
  • Save jzempel/3160842 to your computer and use it in GitHub Desktop.
Save jzempel/3160842 to your computer and use it in GitHub Desktop.
Duck, Duck, Survivor
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