The birthday: I always win!
9 guests and the birthday person: 10 people. The birthday age is 12, so K = 12. Reconstruct the seat that leaves this person last.
Algorithms
Choose the result and reconstruct the starting state: a deck of cards or a Josephus circle. Watch, pause and undo every move.
Read the explanation and the two problemsForward: take from the bottom, place on top; take from the bottom, place on the table. Backward: take back from the table, place underneath; take from the top, place underneath.
9 guests and the birthday person: 10 people. The birthday age is 12, so K = 12. Reconstruct the seat that leaves this person last.
20 friends, 2 winners and K = 11. Find the two seats to give the pair before starting.
Gather the winners. The next loser enters as a provisional number with ?, moves backward with each count, and is confirmed where it arrives. The next round starts again from the last inserted loser. Only at the end do we find seat 1 and number the seats.
Reduced motion is enabled. To watch the transfer, select this checkbox.
Desired removals, first to last
Observed removals, first to last
Prepared deck, top to bottom
Position labels are counted from the bottom: simulate the game, then assign each position the value required when it is removed.
| Removed position (from bottom) | Value to assign |
|---|
Number with ? → move with each count → confirm in the same spot → restart from the last inserted loser. Numbers without ? stay fixed.
▼ Initial reference: person 1 stays at the top
Only the provisional number with ? moves. The circle rotates only at the end.
For many numbers, scroll inside the circle to see them all.
The number with ? enters provisionally and moves one gap with each count; all other numbers stay fixed. At count K the ? disappears and the loser is confirmed exactly there. The next start is the last inserted loser. To preserve every identity in the PHP array, the first provisional position is prepared in advance: with 15 winners and K = 9 it starts before 9 and arrives before 1. After the last insertion, a separate count, again from the last loser, locates seat 1; only then is the complete circle rotated and numbered. The final order matches the PHP loop.
Numbers now denote seats: green = winner, blue = loser. Seat 1 is where counting starts for elimination; it is not the identifying label of person 1.
Seats are numbered clockwise. Counting for elimination starts at seat 1 and follows the chosen direction; after each elimination it restarts with the next person.
Queue in counting order, starting with the next 1