The Josephus problem
Asked at Jane Street, Citadel
people stand in a circle, numbered to clockwise. Starting the count at person , every second person is eliminated ( goes first, then , and so on), continuing around and around the shrinking circle until only one person remains.
For a given , which position survives? Work it out for , and find the general rule.
Show a hint
Look for a pattern when is a power of 2. Then write and see what the "extra" people do to the answer.