I'm very new to python and programming so bear with me =]
I'm trying to write a code for a scenario a friend came up with.
Game:
Pick a number for an amount of participants in a group.
Pick a random number
Line the participates up and then remove the participate in which the "random number" falls on. Then starting from the next person in line, use the same "random number" to remove the next person. This cycles through the group until there is one remaining.
Example would be :
group = 5
number_picked = 3
So, [0,1,2,3,4] would remove(or pop) the 3rd person and look like so [0,1,3,4].
Then STARTING at 3, you would count 3 again and remove person 0 as that is were the next person selected falls in the cycle. Which would look like [1,3,4].
Then it would be [1,3] and finally [3]. So 3 would be the winner.
Here is the code i currently have:
amount_in_group = int(input("How many people in the group? \n"))
number_picked = int(input("select a number: \n"))
group = [i for i in range((amount_in_group))]
print(group)
while group.__len__() != 1:
if number_picked > group.__len__():
index_position = number_picked % group.__len__()
group.pop(index_position -1)
# print(group)
elif group.__len__() >= number_picked:
group.pop(number_picked -1)
# print(group)
## winner is ##
print(group)
I feel like I am close but the issue with my code is every time a number is popped it starts back at index 0 and counts from there. I need it to pop an index and then START from the next position and cycle through the list until 1 is left! Any help would be greatly appreciated!