37 AD · Jotapata · 40 soldiers · 1 MATHEMATICAL GENIUS
Figure out where to stand before the clock runs out!
Josephus and his soldiers were trapped by the Romans. They chose to eliminate each other in a circle rather than surrender — counting every k-th person. Josephus calculated the exact safe position. He alone survived to tell the tale.
Your name shall be remembered by history
In 37 AD, historian Flavius Josephus was besieged at Jotapata. Trapped in a cave with 40 soldiers, they formed a grim pact rather than surrender to Rome:
Josephus calculated exactly where to stand to survive. He walked out alive — and wrote about it!
Example: n = 5 soldiers, step k = 2.
Circle: [1, 2, 3, 4, 5]
So J(5, 2) = 3.
For k = 2, there's a slick formula. Find the largest power of 2 ≤ n (call it 2^m), then L = n − 2^m:
For any k, use the iterative formula (O(n) time):
Check: josephus(5, 2) = 3 ✓
All four circles conquered. Josephus himself would bow to you!