Last active
August 22, 2018 22:40
-
-
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
This file contains hidden or 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
| #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