Skip to content

Instantly share code, notes, and snippets.

@pranavgarg
Last active October 14, 2016 20:29
Show Gist options
  • Save pranavgarg/8eaaa2ddbfb47456868771eb51034b69 to your computer and use it in GitHub Desktop.
Save pranavgarg/8eaaa2ddbfb47456868771eb51034b69 to your computer and use it in GitHub Desktop.
josepheus problem - delete every 3rd element until the list goes empty
a = ['1','2','3','4','5','6','7','8','9']
def josepheus(int_list, skip):
skip = skip - 1 #list starts with 0 index
idx = 0
output = []
while len(int_list)>0:
idx = (skip+idx)%len(int_list)
k = int_list.pop(idx)
output.append(k)
return output
assert josepheus(a,3)==['3','6','9','4','8','5','2','7','1']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment