💀

Josephus survived
the permutation massacre.
Will you?

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.

4 Battle Levels
Click the Circle
Beat the Clock
Free Tutorial
1
2
3
4
📖
4 Levels + Tutorial

Join the Circle!

Your name shall be remembered by history

Tell us who you are
?
Progress 0 / 4 cleared
Choose Your Battle!
4 levels of circle chaos — unlock the secret archive
LEVEL 1
Time remaining
The Ancient Algorithm

The Ancient Problem

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:

  • Stand in a circle, numbered 1 to n.
  • Starting from position 1, count every k-th soldier.
  • That soldier is eliminated — counting restarts from the next.
  • Last one standing survives.

Josephus calculated exactly where to stand to survive. He walked out alive — and wrote about it!

How It Works

Example: n = 5 soldiers, step k = 2.

Circle: [1, 2, 3, 4, 5]

  • Count 2 from start → eliminate 2 → [1, 3, 4, 5]
  • Count 2 from 3 → eliminate 4 → [1, 3, 5]
  • Count 2 from 5 → eliminate 1 → [3, 5]
  • Count 2 from 3 → eliminate 5 → Survivor: 3!

So J(5, 2) = 3.

The Algorithm

For k = 2, there's a slick formula. Find the largest power of 2 ≤ n (call it 2^m), then L = n − 2^m:

J(n, 2) = 2L + 1

For any k, use the iterative formula (O(n) time):

function josephus(n, k) {
  let s = 0;
  for (let i = 2; i <= n; i++) {
    s = (s + k) % i;
  }
  return s + 1; // 1-indexed
}

Check: josephus(5, 2) = 3

Live Simulator

8
2
Safe Position
Press Simulate!
Step 1 of 4
🏆

You Survived!

All four circles conquered. Josephus himself would bow to you!

0 Total Stars
4 Levels Cleared
UNLOCK REWARD — Learn the Algorithm!