people children stand in a circle, numbered clockwise from 1 to people; player 1 comes right after player people. They play a counting-out game:
1. Counting starts at player 1.
2. Count step players clockwise, including the one you start on. The count wraps around the circle, so some players may be counted twice.
3. The last player counted leaves the circle.
4. If more than one player remains, the next count starts at the player immediately clockwise of the one who just left, and the process repeats.
Return the number of the player who is left last in the circle.people=4, step=3 → 1
Count 1, 2, 3: player 3 is out. Then 4, 1, 2: player 2 is out. Then 4, 1, 4: player 4 is out. Player 1 is left.
people=6, step=1 → 6
Each count knocks out the player it starts on, so players leave in order and 6 is the last one standing.
people=4, step=3
1
Run checks the first 3 tests in your browser. Submit checks all 85 tests on the server, hidden ones included.