1. Home
  2. Numberphile

Oct 27, 2016

The binary trick that solves the deadly Josephus problem

13 min → 1:37

Overview

The speaker explores the Josephus Problem, using small examples, pattern tables, and a binary number trick to find which position in a circle of soldiers survives systematic elimination.

3 things to know

Numberphile: The Josephus Problem removes every second item in circles

Numberphile explains the Josephus Problem, where items sit in a circle and every second remaining item is removed each round until only one survivor is left.

More

A theoretical problem where 'n' items are arranged in a circle. The goal is to find the starting position of that final survivor.

▶ Watch at 0:34

Moving the first binary digit to the end finds winners

Numberphile shares a binary shortcut where converting the soldier count to binary and moving the leading one to the end reveals the winning position.

More

The problem has an elegant shortcut using binary numbers.

▶ Watch at 12:44

Numberphile says a remainder after powers of two finds survivors

Numberphile expresses the winning spot as two times a remainder plus one, after subtracting the largest power of two from the total number of soldiers.

More

The solution is expressed with the formula `W(n) = 2l + 1`, where 'n' is written as `n = 2^a + l`.

Also in this episode

Powers of Two

A critical insight is that whenever the number of soldiers 'n' is a power of two (e.g., 2, 4, 8, 16), the survivor is always the person in the first position.

Testing 1, 2, or 3 soldiers reveals the winning pattern

Numberphile shows a method that solves the puzzle for small numbers of soldiers like 1, 2, and 3 to record the winning spots and find a sequence.

Quotes

“...the winning solution in binary is you take the leading digit and you put it at the end.”

▶ Watch at 12:44

“And so he wanted to figure out where should he sit within this circle in order to be the last man living.”

▶ Watch at 0:34

“And he suggested what we should do is we should gather data. Just take various values of n and just do it by hand and start looking for a pattern.”

▶ Watch at 1:44

Full summary

Episode Overview

  • The episode introduces the "Josephus Problem," a mathematical puzzle based on a historical story about soldiers in a circle choosing to avoid capture by systematically eliminating each other.
  • The core of the problem is to determine which position in the circle will be the last one remaining for any given number of soldiers (n).
  • The speaker demonstrates a practical approach to solving the problem by starting with small examples, gathering data in a table, and identifying patterns.
  • A general formula is derived, which is then connected to a surprisingly simple and elegant trick using binary numbers to find the survivor's position instantly.

Key Concepts

  • The Josephus Problem: A theoretical problem where 'n' items are arranged in a circle. In each round, every second remaining item is removed until only one is left. The goal is to find the starting position of that final survivor.
  • Data Gathering and Pattern Recognition: The speaker's method involves solving the problem for small numbers of soldiers (n=1, 2, 3, etc.), recording the winning position for each 'n', and analyzing the resulting sequence to discover a pattern.
  • Powers of Two: A critical insight is that whenever the number of soldiers 'n' is a power of two (e.g., 2, 4, 8, 16), the survivor is always the person in the first position.
  • General Formula: The solution is expressed with the formula W(n) = 2l + 1, where 'n' is written as n = 2^a + l. Here, 2^a is the largest power of two less than 'n', and l is the remainder.
  • Binary Notation Trick: The problem has an elegant shortcut using binary numbers. To find the winning position, you convert the total number of soldiers 'n' to its binary representation, move the first digit ('1') to the end of the string, and convert the new binary number back to decimal.

Quotes

  • At 00:34 - "And so he wanted to figure out where should he sit within this circle in order to be the last man living." - Explaining the historical motivation of Josephus, who preferred capture over suicide and needed to calculate the safe position.
  • At 01:44 - "And he suggested what we should do is we should gather data. Just take various values of n and just do it by hand and start looking for a pattern." - Describing the fundamental mathematical problem-solving technique of starting with simple examples to uncover a general rule.
  • At 12:44 - "...the winning solution in binary is you take the leading digit and you put it at the end." - Revealing the simple and powerful trick using binary numbers to solve the problem for any number of soldiers.

Takeaways

  • To solve complex problems, start with the simplest possible cases. By manually working through the problem for small numbers and recording the results, you can gather data that reveals underlying patterns and leads to a general solution.
  • Changing your perspective can unlock elegant solutions. Representing the numbers in binary notation transforms a complex, iterative problem into a simple manipulation of digits, highlighting how different mathematical representations can offer unique insights.
  • Decomposing a problem relative to a known simple case is a powerful strategy. By expressing any number 'n' in terms of the nearest smaller power of two (the simplest case), the solution becomes a straightforward calculation based on the remainder.

Watch the full episode 13 min

Read along with the audio summary

In a circle of soldiers eliminating each other to avoid capture, the speaker notes that Josephus preferred capture over suicide and needed to calculate where to sit to be the last man living. In this episode that came out on October 27, 2016, the speaker breaks down this classic mathematical puzzle.

The puzzle of the final survivor reveals how a life or death story becomes a math problem. This is the Josephus Problem, where a set number of items, called n, are arranged in a circle, and the goal is to find the starting position of the final survivor.

Starting small unlocks complex patterns. By solving the problem for one, two, or three soldiers and recording each winning spot in a table, you can analyze the resulting sequence to discover a pattern.

This table reveals how powers of two guarantee a safe spot right at the start. Whenever the total number of soldiers is a power of two, like two, four, or eight, the pattern resets. In all of these cases, the survivor is always the person in the very first position.

Knowing that reset point leads to a general formula for any circle size. You can break any number of soldiers down into the largest power of two that fits inside it, plus whatever is left over, called the remainder. The winning position is simply two times that remainder, plus one.

A binary notation trick offers an even faster shortcut. You convert the total number of soldiers into binary, move the leading digit one to the end of the string, and convert that new binary number back into a regular decimal number to get the winning spot.

Changing your perspective can unlock elegant solutions, and representing numbers in binary transforms a complex, repetitive problem into a simple manipulation of digits. The winning solution in binary is you take the leading digit and you put it at the end.

More from Numberphile

Related Episodes