Introduction
In this challenge, your task is to simulate a certain type of elimination game.
In the game, the participants stand in a circle, and everyone is holding an integer.
On each round of the game, every participant points at the person n
steps away, if n
is the number they are holding. If n
is positive, they count to their right, if n
is negative, they count to their left, and if n
is zero, they point at themselves.
Every participant who has someone pointing at them is eliminated, and leaves the circle; this ends the round.
The rounds continue until there are no participants left.
Input
Your input is a non-empty list of integers, in any reasonable format. It represents the numbers that the participants of the game are holding.
Output
Your output is the number of rounds it takes until the game ends.
Example
Consider the input list [3,1,-2,0,8]
.
On the first round, the following happens:
- The person holding
3
points right at the person holding0
. - The person holding
1
points right at the person holding-2
. - The person holding
-2
points left at the person holding3
. - The person holding
0
points at themself. - The person holding
8
points right at the person holding-2
(the list represents a circle, so it wraps around at the ends).
This means that 0
, -2
and 3
are eliminated, so the second round is done with the list [1,8]
.
Here, 1
points at 8
, and 8
points at themself, so 8
is eliminated.
The third round is done with the list [1]
, where 1
simply points at themself and is eliminated.
It took three rounds to eliminate all participants, so the correct output is 3
.
Rules and scoring
You can write a full program or a function. The lowest byte count wins, and standard loopholes are disallowed.
Test cases
[3] -> 1
[0,0,0] -> 1
[-2,-1,0,1,2,3,4,5,6,7] -> 2
[5,5,5,6,6,6] -> 2
[3,-7,-13,18,-10,8] -> 2
[-7,5,1,-5,-13,-10,9] -> 2
[4,20,19,16,8,-9,-14,-2,17,7,2,-2,10,0,18,-5,-5,20] -> 3
[11,2,7,-6,-15,-8,15,-12,-2,-8,-17,6,-6,-5,0,-20,-2,11,1] -> 4
[2,-12,-11,7,-16,9,15,-10,7,3,-17,18,6,6,13,0,18,10,-7,-1] -> 3
[18,-18,-16,-2,-19,1,-9,-18,2,1,6,-15,12,3,-10,8,-3,7,-4,-11,5,-15,17,17,-20,11,-13,9,15] -> 6
n
is the number the person is holding? \$\endgroup\$