Numberphile
Eliminating the remainder beyond the largest power of two guarantees victory to seat 2ℓ + 1 because the sword holder never relinquishes control in a power-of-two group, an outcome calculable by moving the leading binary bit to the end.
AI-assisted summary of The Josephus Problem - Numberphile — original source. Check the original for full context.
Source published:
Key ideas
- The classic Josephus elimination problem guarantees that surviving seats are always odd numbers, as every even seat is eliminated in the very first rotation. (1:52)
- Whenever the total number of people in the circle is a pure power of two ($n = 2^a$), seat 1 is mathematically guaranteed to survive. (4:30)
- For any arbitrary group size expressed as $n = 2^a + \ell$, eliminating $\ell$ people reduces the circle to an exact power of two, making seat $2\ell + 1$ the ultimate winner. (6:37)
- In binary representation, the winning position $W(n)$ can be determined instantly by performing a one-bit cyclic left shift, moving the leading '1' to the least significant digit. (11:55)
Detailed notes
## Background Published on YouTube by the educational channel Numberphile on October 28, 2016, this video features mathematician Daniel Erman from the University of Wisconsin–Madison. Supported by the Mathematical Sciences Research Institute (MSRI) and created by Brady Haran, the presentation explores the historical mathematics puzzle known as the Josephus Problem.
## TL;DR Daniel Erman introduces the Josephus Problem, a puzzle based on an ancient suicide pact where soldiers arranged in a circle eliminate their neighbors until a lone survivor remains. By tabulating small test cases by hand, Erman demonstrates that winning seats are always odd and reset to position 1 whenever the group size is a pure power of two. He establishes the general closed-form formula $W(n) = 2\ell + 1$ by decomposing $n$ into $2^a + \ell$, proving it works for the historical 41-person scenario to identify seat 19. Finally, he reveals an elegant computational shortcut where the winning position can be found simply by cyclically shifting the leading binary bit of $n$ to the end.
## Atmosphere & style The presentation feels casual, collegiate, and infectious, capturing the spirit of an engaging one-on-one tutorial sketched out with Sharpies on brown butcher paper. Host Brady Haran provides curious, playful interjections that mirror the viewer's learning curve, transitioning from lighthearted jokes about staying out of even-numbered seats to genuine excitement when his manual calculations succeed. Erman radiates infectious enthusiasm as an educator, seamlessly turning a dark historical anecdote into an accessible, rewarding exploration of pattern recognition and binary arithmetic.
## Bulletin - [01:52](https://www.youtube.com/watch?v=uCsD3ZGzMgE&t=112s) The classic Josephus elimination problem guarantees that surviving seats are always odd numbers, as every even seat is eliminated in the very first rotation. - [04:30](https://www.youtube.com/watch?v=uCsD3ZGzMgE&t=270s) Whenever the total number of people in the circle is a pure power of two ($n = 2^a$), seat 1 is mathematically guaranteed to survive. - [06:37](https://www.youtube.com/watch?v=uCsD3ZGzMgE&t=397s) For any arbitrary group size expressed as $n = 2^a + \ell$, eliminating $\ell$ people reduces the circle to an exact power of two, making seat $2\ell + 1$ the ultimate winner. - [11:55](https://www.youtube.com/watch?v=uCsD3ZGzMgE&t=715s) In binary representation, the winning position $W(n)$ can be determined instantly by performing a one-bit cyclic left shift, moving the leading '1' to the least significant digit.
## Key takeaways - [00:00](https://www.youtube.com/watch?v=uCsD3ZGzMgE&t=0s) The Josephus Problem originates from a historical suicide pact among Jewish soldiers avoiding Roman capture, where Josephus needed to calculate the single surviving position to surrender instead of dying. - [00:00](https://www.youtube.com/watch?v=uCsD3ZGzMgE&t=0s) For an initial example of 7 people, step-by-step clockwise elimination wraps around the circle and leaves person 7 as the sole survivor. - [01:52](https://www.youtube.com/watch?v=uCsD3ZGzMgE&t=112s) Gathering data for small values reveals that the winning seat is always an odd number because all even-numbered seats are eliminated in the very first cycle. - [02:55](https://www.youtube.com/watch?v=uCsD3ZGzMgE&t=175s) The sequence of winners increases by increments of two ($1; 1, 3; 1, 3, 5, 7\dots$), periodically resetting back to 1. - [04:30](https://www.youtube.com/watch?v=uCsD3ZGzMgE&t=270s) The resets to seat 1 occur exclusively when the total number of participants $n$ is a pure power of two ($1, 2, 4, 8, 16$). - [04:30](https://www.youtube.com/watch?v=uCsD3ZGzMgE&t=270s) When $n = 2^a$, a complete round eliminates half the participants while returning the sword to person 1, recursively reducing the group until person 1 wins. - [06:37](https://www.youtube.com/watch?v=uCsD3ZGzMgE&t=397s) Any positive integer $n$ can be broken down as $2^a + \ell$, where $2^a$ is the largest power of two less than or equal to $n$ and $\ell < 2^a$ is the leftover remainder. - [06:37](https://www.youtube.com/watch?v=uCsD3ZGzMgE&t=397s) After exactly $\ell$ eliminations, the circle is reduced to $2^a$ survivors, meaning whoever holds the sword at that exact moment (seat $2\ell + 1$) is guaranteed to win. - [06:37](https://www.youtube.com/watch?v=uCsD3ZGzMgE&t=397s) Applying the general formula $W(n) = 2\ell + 1$ to $n = 13$ ($8 + 5$) yields winning seat $2(5) + 1 = 11$, which matches manual simulation. - [10:12](https://www.youtube.com/watch?v=uCsD3ZGzMgE&t=612s) For the historical 41-person scenario ($32 + 9$), the formula yields $2(9) + 1 = 19$, identifying seat 19 as the safe position. - [11:55](https://www.youtube.com/watch?v=uCsD3ZGzMgE&t=715s) The problem has a direct binary shortcut: expressing $n$ in binary and shifting the leading '1' to the far-right end directly yields the binary value of the winning seat. - [11:55](https://www.youtube.com/watch?v=uCsD3ZGzMgE&t=715s) Applying the binary cyclic shift to 41 (`101001`) shifts the leading 1 to the end, producing `010011`, which equals 19 in decimal.
## Detailed walkthrough ### [00:00](https://www.youtube.com/watch?v=uCsD3ZGzMgE&t=0s) The Historical Legend and the Small Example
Daniel Erman introduces the famous mathematical puzzle known as the Josephus Problem, which takes its inspiration from a grim historical story. According to the legend Erman was told, a company of Jewish soldiers found themselves surrounded by the Roman army and resolved to avoid capture through a collective suicide pact. Arranging themselves in a circle, the first man used his sword to kill the person directly to his left. The next remaining living person then executed the person to his left, continuing in a lethal cycle until only a single survivor remained, who was expected to commit suicide rather than surrender. However, the soldier Josephus secretly preferred being captured to dying. Because openly expressing that preference would have caused the other soldiers to turn on him immediately, Josephus faced a life-or-death calculation: he had to figure out where to sit in the circle so that he would be the final person left alive, allowing him to surrender instead of taking his own life.
```mermaid flowchart TD accTitle: The Josephus Elimination Process for 7 People accDescr: Elimination order for seven soldiers showing how person 7 is the sole survivor. subgraph Round1["Round 1"] A["1 kills 2"] --> B["3 kills 4"] B --> C["5 kills 6"] C --> D["7 kills 1"] end subgraph Round2["Round 2"] D --> E["3 kills 5"] end subgraph Round3["Final Round"] E --> F["7 kills 3"] F --> G["7 Survives!"] end ```
To illustrate how tricky the problem becomes as the circle wraps around, Erman works out a small case with seven people. Person 1 executes 2, person 3 executes 4, and person 5 executes 6. At this stage, because there is no person 8, the cycle wraps back to the front: person 7 kills person 1. The turn then advances to the next survivor, person 3, who kills person 5. Finally, person 7 eliminates person 3, leaving 7 as the winner. In the historical account, Josephus was dealing with a circle of 41 people, but the general mathematical challenge is to determine the winning seat $W(n)$ for any arbitrary group of $n$ people.
- Erman notes that in high school, this puzzle was one of the key milestones that taught him how to approach math problems when nobody has shown you the answer beforehand. - He credits his former professor, Phil Hanlon, with steering him toward mathematics and teaching him the foundational strategy of gathering data by hand to look for patterns.
---
[01:52](https://www.youtube.com/watch?v=uCsD3ZGzMgE&t=112s) Gathering Data and Spotting Odd Winners
Following Hanlon's method, Erman sets up a table of data, defining $n$ as the total number of seats and $W(n)$ as the winning seat number. From the initial demonstration, it is already established that for $n = 7$, $W(7) = 7$. Testing smaller values by hand, Erman examines $n = 5$: 1 kills 2, 3 kills 4, 5 kills 1, and 3 kills 5, leaving 3 as the victor ($W(5) = 3$). Filling in $n = 6$, person 1 executes 2, 3 executes 4, 5 executes 6, 1 executes 3, and 5 executes 1, making 5 the winner ($W(6) = 5$).
| $n$ (seats) | $W(n)$ (winner) | |:---:|:---:| | 1 | 1 | | 2 | 1 | | 3 | 3 | | 4 | 1 | | 5 | 3 | | 6 | 5 | | 7 | 7 | | 8 | 1 |
Immediately, a striking pattern emerges: the winning seat is always an odd number. Erman explains why this happens almost effortlessly: during the very first pass around the circle, every person in an even-numbered seat is struck down. Brady Haran jokingly interjects to clarify the practical survival rule: “So you DON'T want to sit in an even seat?”, to which Erman adamantly replies, “Don't sit in an even seat, no no no.”
---
[02:55](https://www.youtube.com/watch?v=uCsD3ZGzMgE&t=175s) Tabulating Results and Predicting the Sequence
Erman proceeds to systematically compute the earliest values to establish a baseline: - For $n = 1$, the lone individual survives by default ($W(1) = 1$). - For $n = 2$, 1 kills 2, so 1 wins ($W(2) = 1$). - For $n = 3$, 1 kills 2, then 3 kills 1, leaving 3 ($W(3) = 3$). - For $n = 4$, 1 kills 2, 3 kills 4, and 1 kills 3, giving 1 ($W(4) = 1$). - For $n = 8$, after 1 kills 2, 3 kills 4, 5 kills 6, and 7 kills 8, the remaining circle $\{1, 3, 5, 7\}$ sees 1 kill 3, 5 kill 7, and finally 1 kill 5, leaving 1 ($W(8) = 1$).
Writing out the winners reveals an escalating series of odd numbers that periodically resets: $1; 1, 3; 1, 3, 5, 7; 1, 3, 5, 7, 9\dots$ Brady attempts to anticipate the pattern by asking whether $n = 13$ resets back to 1. Erman responds, “NO! Good guess actually! But it is not a one.” The sequence climbs by twos on each step, and Erman demonstrates that it will not reset at 13 or 14—in fact, for $n = 14$, the winner is 13. He emphasizes that even if they cannot immediately calculate a distant value like $n = 178$, observing this behavior allows them to form testable predictions.
---
[04:30](https://www.youtube.com/watch?v=uCsD3ZGzMgE&t=270s) Powers of Two and the First Theorem
Returning to Brady's hypothesis about when the sequence resets, Erman points out that the resets to seat 1 occur exclusively when $n$ is a pure power of two ($n = 1, 2, 4, 8, 16$). He reflects on how Professor Hanlon pushed his students when they felt frustrated by not yet having a total formula: “If you know something... Prove it, and make sure you really understand that one thing, and that often unlocks the rest.”
Following this advice, Erman formulates a formal conjecture: “If $n$ is a pure power of two, then the winning seat is one.” To prove this, he sets up the case for $n = 16$. As person 1 starts, a complete pass around the circle eliminates every even seat up to 16, with 15 executing 16. At that moment, exactly half the people have died, leaving 8 people, and the turn returns cleanly to person 1. Relabeling the survivors effectively resets the game into an 8-person circle where person 1 still holds the sword. Repeating the exact same cycle reduces 8 people to 4, then 4 to 2, and finally 2 to 1, with person 1 retaining the turn at every transition. Because the sword never leaves person 1's cycle, seat 1 is guaranteed to win whenever $n$ is a power of two.
---
[06:37](https://www.youtube.com/watch?v=uCsD3ZGzMgE&t=397s) The General Formula: $n = 2^a + \ell$
Having resolved the behavior for pure powers of two, Erman turns to the numbers lying between them, where the winning seat climbs by increments of two before resetting. He notes that any positive integer can be uniquely represented as a sum of distinct powers of two via its binary expansion. By isolating the single largest power of two that fits inside $n$, any number can be written as: $$n = 2^a + \ell$$ where $2^a$ is the largest power of two less than or equal to $n$, and $\ell$ is the leftover remainder (with $\ell < 2^a$). For instance, taking $n = 77$, the largest power of two is $64$, leaving a remainder of $13$ (which itself is $8 + 4 + 1$).
```mermaid flowchart LR accTitle: Decomposition of n into Power of Two and Remainder accDescr: Flow diagram showing how eliminating L people reduces the circle to a power of two where the next person wins. A["Total People: n = 2^a + L"] -->|"Eliminate L people (2L eliminated/active)"| B["L eliminations complete"] B --> C["Power of Two (2^a) people remain"] C --> D["Next person to strike: Seat 2L + 1"] D --> E["Seat 2L + 1 wins the entire game"] ```
Erman explains that the remainder $\ell$ directly controls which odd seat survives. He illustrates this by testing $n = 13$, which decomposes into $2^3 + 5$ (so $2^a = 8$ and $\ell = 5$): - Execute exactly $\ell = 5$ steps: 1 kills 2, 3 kills 4, 5 kills 6, 7 kills 8, and 9 kills 10. - Exactly 5 people have been killed, leaving $13 - 5 = 8$ people remaining in the circle. - Since 8 is a pure power of two, the dynamics of the previous theorem take over: whoever holds the sword at this precise instant will win the game. Brady remarks, “The first killer,” and Erman confirms: “The first killer! So now, if we go from here I claim that eleven is going to win.” - Tracing it out: 11 kills 12, 13 kills 1, 3 kills 5, and 7 kills 9, cycling back to 11 with 4 people left; 11 kills 13 and 3 kills 7, leaving 2 people; 11 strikes the final blow and wins.
Erman formalizes this into the general theorem: if $n = 2^a + \ell$ with $\ell < 2^a$, then after $\ell$ kills, the turn falls on person $2\ell + 1$. Because there are exactly $2^a$ soldiers remaining at that point, that person will sweep the rest of the game, proving that the winning seat is always: $$W(n) = 2\ell + 1$$ For $n = 13$, where $\ell = 5$, the formula yields $2(5) + 1 = 11$, precisely matching the manual calculation.
[10:12](https://www.youtube.com/watch?v=uCsD3ZGzMgE&t=612s) Applying the Formula to the 41-Person Cave Problem
Having established that whenever the group size is a pure power of two, the person holding the sword first wins, Brady Haran eagerly tests his understanding on the original historical riddle. In the legend, Josephus was trapped with 40 fellow soldiers, making a total of $n = 41$ people. Brady breaks down the number using Daniel Erman’s framework $n = 2^a + \ell$: the largest power of two less than or equal to 41 is 32 ($2^5$), leaving a remainder of $\ell = 9$. Using the formula $W(n) = 2\ell + 1$, Brady calculates two lots of 9 plus 1, arriving at position 19 as the winning seat.
To verify the arithmetic, Daniel sketches out a circle of 41 numbered seats on paper, joking along the way as the numbers crowd together near the end. As Daniel crowds the digits, Brady quips, “Look at that, this is a lesson about planning ahead, people.” They simulate the elimination step-by-step: person 1 eliminates person 2, person 3 eliminates person 4, stripping away all even numbers along the way. After person 40 is eliminated, person 41 eliminates person 1. The cycle continues around the circle until person 19 executes person 35, leaving position 19 as the final survivor and confirming Brady's calculation.
```mermaid flowchart LR accTitle: Josephus Formula Calculation for 41 People accDescr: Flow diagram showing how 41 is decomposed into a power of 2 plus remainder, yielding seat 19 via the formula 2l + 1. subgraph Inputs["Decomposition"] A["n = 41"] --> B["2^5 = 32"] A --> C["Remainder ℓ = 9"] end subgraph Formula["Evaluation"] C --> D["2ℓ + 1"] D --> E["2(9) + 1 = 19"] end E --> F["Winning Seat: 19"] ```
- Total group size: $n = 41$ (Josephus plus 40 soldiers). - Largest power of two: $2^a = 32$, with $\ell = 9$ (since $41 = 32 + 9$). - Winning seat formula: $2\ell + 1 = 2(9) + 1 = 19$. - Full-sentence quote: Brady proudly exclaims, “I was right!” when 19 survives the simulation, to which Daniel replies, “There we go, nineteen!”
---
[11:55](https://www.youtube.com/watch?v=uCsD3ZGzMgE&t=715s) The Binary Shortcut and Closing Credits
Daniel points out an elegant alternative method: interpreting the problem using binary notation. Any integer can be expressed as a sum of powers of two, meaning 41 is written as $32 + 8 + 1$, or $2^5 + 2^3 + 2^0$. In standard binary representation, with digits corresponding to powers of two from $2^5$ down to $2^0$, 41 translates to `101001`.
```mermaid flowchart LR accTitle: Binary Cyclic Bit Shift for Josephus Problem accDescr: Diagram illustrating the cyclic left bit shift where the leading 1 of 41 in binary moves to the end, resulting in 19. subgraph Binary41["Binary of 41"] B1["1"] --- B2["01001"] end subgraph Shift["Bit Shift Operation"] B1 -.->|"Shift leading bit to the end"| S1["1"] B2 --> S2["01001"] end subgraph Binary19["Resulting Binary"] S2 --- S1 S2 --> R["010011_2 = 19"] end ```
Daniel reveals a fast arithmetic trick: to determine the winning position $W(n)$, simply take the leading binary digit (the initial `1`) and cycle it to the very end of the binary string. Moving the leading `1` of `101001` to the far right produces `010011`. Converting `010011` back to base ten gives $2^4 + 2^1 + 2^0 = 16 + 2 + 1 = 19$, matching the exact winning chair. Daniel highlights how this cyclic shift provides a direct leap from $n$ to $W(n)$, remarking that the underlying structure would have been instantly visible had the values been recorded in binary from the start.
- Binary of 41: $2^5 + 0\cdot2^4 + 2^3 + 0\cdot2^2 + 0\cdot2^1 + 2^0 = 101001_2$. - Cyclic shift rule: Strip the leading `1` and append it to the right: $101001 \to 010011$. - Base-10 conversion of shifted binary: $2^4 + 2^1 + 2^0 = 16 + 2 + 1 = 19$. - Full-sentence quote: Daniel explains, “The way to find the winning solution if this is n, the winning solution in binary is you take the leading digit and you put it at the end.” - Full-sentence quote: Wrapping up the binary demonstration, Daniel enthuses, “So if you're writing your numbers in binary code, the pattern would've been even more quickly apparent.” - Filming location: Mathematical Sciences Research Institute (MSRI), which supports both high-level mathematical research and outreach initiatives like Numberphile.
## Notable quotes > [04:30](https://www.youtube.com/watch?v=uCsD3ZGzMgE&t=270s) If you know something... Prove it, and make sure you really understand that one thing, and that often unlocks the rest. — Phil Hanlon
## Mentioned Daniel Erman, Brady Haran, Josephus, Phil Hanlon, University of Wisconsin-Madison, Mathematical Sciences Research Institute (MSRI), Numberphile
## Video description The Josephus Problem, featuring Daniel Erman from University of Wisconsin-Madison. Winning at Dots and Boxes: https://youtu.be/KboGyIilP6k More links & stuff in full description below ↓↓↓
Correction: Around 9:40 that should be L less than 2^a NOT 2a --- Sorry, typo in editing! But you got the point hopefully.
Support us on Patreon: http://www.patreon.com/numberphile
NUMBERPHILE Website: http://www.numberphile.com/ Numberphile on Facebook: http://www.facebook.com/numberphile Numberphile tweets: https://twitter.com/numberphile Subscribe: http://bit.ly/Numberphile_Sub
Numberphile is supported by the Mathematical Sciences Research Institute (MSRI): http://bit.ly/MSRINumberphile
Videos by Brady Haran
Brady's videos subreddit: http://www.reddit.com/r/BradyHaran/
Brady's latest videos across all channels: http://www.bradyharanblog.com/
Sign up for (occasional) emails: http://eepurl.com/YdjL9
Numberphile T-Shirts: https://teespring.com/stores/numberphile Other merchandise: https://store.dftba.com/collections/numberphile
[Source](https://www.youtube.com/watch?v=uCsD3ZGzMgE)