Skip to content

Instantly share code, notes, and snippets.

@paulosuzart
Last active November 18, 2018 22:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulosuzart/6b2fd3e063f379bbf4c99a72343db374 to your computer and use it in GitHub Desktop.
Save paulosuzart/6b2fd3e063f379bbf4c99a72343db374 to your computer and use it in GitHub Desktop.
solve_students.py
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