The Josephus Problem

People stand in a circle; going around, every second person is eliminated until one remains. Flavius Josephus, so the story goes, computed the safe position in a hurry. The survivor's position bounces around chaotically as the circle grows — until you write the count in binary, move the leading 1 to the end, and the chaos collapses into a party trick.

view
Circle of 12 seats
Click any dot in the ring — that's where you stand. Then run the count: starting at seat 1, every second person is out, round and round, until one remains.
circle size
the count
speed

Powers of two are clean restarts. Send the sweep once around a circle of 2^m people and it takes exactly the even seats — half the circle, no seat counted twice, no seat missed — and it hands the count straight back to whoever started. Renumber the survivors and you are playing the same game at half the size, with the same person going first. So in a power-of-two circle, the person the count starts on wins.

Any other n is a power of two plus a leftover l. The first l eliminations are pure trimming: they shave the circle down to the nearest clean size below. The price is that the count no longer starts at seat 1 — it has walked past 2l seats, so it restarts on seat 2l + 1. That seat is now "whoever starts", and whoever starts a power-of-two circle wins.

Doubling and adding one is what binary does for free: to double a number you shift its bits up, and adding one fills the empty slot. Strip the leading 1 (that's the 2^m you subtracted), shift, set the last bit — which is exactly "move the front bit to the back".