Skip to content

Instantly share code, notes, and snippets.

@darkaico
Created March 3, 2017 13:41
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 darkaico/e37ea58cf47f69d51793dcaa38a1931e to your computer and use it in GitHub Desktop.
Save darkaico/e37ea58cf47f69d51793dcaa38a1931e to your computer and use it in GitHub Desktop.
def assign_marker(people_to_mark, marker_index):
result = list(people_to_mark)
for idx, i in enumerate(people_to_mark):
if marker_index < len(result):
marker_index = marker_index + 1
if marker_index < len(result):
del result[marker_index]
else:
del result[0]
break
else:
marker_index = 0
break
if len(result) == 1:
return result[0]
else:
return assign_marker(result, marker_index)
# Tests 4 Personas
# Resultado esperado: 5
people = [i for i in range(1, 5)]
result = assign_marker(people, 0)
print result == 1
# Tests 10 Personas
# Resultado esperado: 5
people = [i for i in range(1, 11)]
result = assign_marker(people, 0)
print result == 5
# 16 personas
# Resultado esperado: 1
people = [i for i in range(1, 17)]
result = assign_marker(people, 0)
print result == 1
# 100 Personas
people = [i for i in range(1, 101)]
result = assign_marker(people, 0)
print 'Result: %s' % result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment