Qm

Where to stand among 1024 pirates

Pirates numbered 1 to n stand in a circle. Pirate 1 shoots pirate 2, pirate 3 shoots pirate 4, and so on round the circle, skipping the dead; whoever is next in line after the last shooter continues, always shooting the next living pirate. This goes on until one pirate is left.

  1. With 1024 pirates, which position survives?
  2. With 1000 pirates? Find a rule that works for any n.
Show a hint

Think about what the circle looks like after one full round when n is a power of two. Then think about what happens after the first few shots when n is not.

Your answer

Solving needs a free account

Answers, streaks and solutions unlock when you are signed in. Reading the question and the hint stays free.

Discussion

Sign in to join the discussion · reading is open to everyone

💡 Discussion rules

  1. No full solutions here. Hints and approaches only.
  2. Complexity, edge cases and intuition are the point.
  3. Interview experiences are welcome. Respect your NDAs.

Loading discussion…

Learn the concepts

The theory behind this question.

Related questions

The Josephus problemFive discs on the Tower of HanoiBinary strings with no two 1s in a row1, 1, 2, 5, 14, 42, what next?Cutting a 4 by 4 by 4 cube when you may restack
All questions →