Imagine you have a circle of people and you go around the circle removing every second person until one person is left.

If you have 3 people in the circle, then the 3rd person will be the last one remaining.

If you have 4 people then the 1st person will be the last one remaining.

If you have 11 people then the 7th person will be the one remaining.

If you have N people in the circle, who will be the last one remaining?

Please formulate your answer as a general solution and not as an algorithm that simulates the problem.


Solution

Solved this puzzle in February. They have removed this challenge from their website.

It’s easy if you do not puzzled by the condition “removing every second person”. Actually, it becomes “skip one person, then insert a new person” if we invert the whole process. You don’t even have to write code to solve it.