Last active
November 18, 2018 22:13
-
-
Save paulosuzart/6b2fd3e063f379bbf4c99a72343db374 to your computer and use it in GitHub Desktop.
solve_students.py
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 solve(students, music): | |
s = students[:] # simply copy the list to not mutate | |
zeroed_music = music - 1 # shit music index to 0 | |
delete_at = zeroed_music % len(s) # decides where to delete mod the size of students | |
while len(s) > 1: | |
print('Considering students %s and index %s' % (s, delete_at)) | |
del s[delete_at] | |
delete_at = (delete_at + zeroed_music) % len(s) | |
return s[0] | |
solve(range(1,11), 3) # must return 4 | |
solve(range(1,101), 2) # must return 73 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment