easy | general |
1024 pirates stand in a circle. They start shooting alternately in a cycle such that the 1st pirate shoots the 2nd, the 3rd shoots the 4th and so on. The pirates who got shot are eliminated from the game. They continue in circles, shooting the next standing pirate, till only one pirate is left. Which position should someone stand to survive?
1024 is a power of 2. Try to find a pattern using smaller powers of 2.
1
Let us try a few numbers.
- For , the person survives by shooting the .
- For , the person survives again.
Let us define "round" as one complete circle of shootings. Logically it makes sense that the first person always survives as the number of people keeps halving evenly in each round. Let us prove this by induction.
Let be the safe position for a given
Base Case: When , we have one pirate . The only pirate, which is the first, is the last to survive, so .
Inductive Step: Assume our hypothesis is true for . That is, .
We need to prove this holds for , i.e. for pirates.
In the first round of shooting, all pirates in even-numbered positions are eliminated. Therefore, at the end of the first round, there are pirates left, all in odd-numbered positions.
Now, the pirates' positions are reset, and the first pirate (who was initially in position 1) is still in position 1.
Therefore, we now have a circle of pirates, starting from the first pirate. The inductive hypothesis states that the first pirate will survive till the end.
Thus, is true for any integer .
For , the position of the surviving pirate would still be the position. Therefore, someone should stand in the first position to survive.
Trivia
-
This problem is called "Josephus problem", named after Flavius Josephus, a Jewish historian living in the century. Allegedly, he and his 40 soldiers were trapped in a cave by Roman soldiers. Preferring suicide instead of being captured, they decided to form a circle and, kill every third soldier until none remained. Josephus, who preferred to surrender, managed to arrange the order of the soldiers in the circle so that he and another man were the last two survivors. At this point, they surrendered to the Romans rather than killing themselves.
-
If is not a power of , then we can use a formula. Find the largest such that .
Take . Then the safe position is .
For example, in the case of 100 pirates (the original puzzle),
The formal proof for this formula can be found here (Wikipedia).