Skip to content

Instantly share code, notes, and snippets.

@lukakostic
Last active August 22, 2018 22:40
Show Gist options
  • Select an option

  • Save lukakostic/490ebeb6d40cab39dccafb078ef186c5 to your computer and use it in GitHub Desktop.

Select an option

Save lukakostic/490ebeb6d40cab39dccafb078ef186c5 to your computer and use it in GitHub Desktop.
Solving: https://www.youtube.com/watch?v=uCsD3ZGzMgE by iteration and not math
#Solving this:
#https://www.youtube.com/watch?v=uCsD3ZGzMgE
#by iteration and not math
def JosephusProblem(n):
people = list(range(1,n+1))
i = 0
while len(people) > 1:
if (i+1)>=(len(people)):
del people[0]
i = 0
else:
del people[i+1]
i+=1
if (i)>(len(people)-1): i = 0
return people[0]
numberOfPeople = 41;
print("Survivor of %d people is at position %d" % (numberOfPeople, JosephusProblem(numberOfPeople)))
while(True): pass #pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment