Josephus Problem

Background: There are countless versions of this problem circulating in the internet. The problem is frequently stated as “100 people standing in a circle waiting to be executed in a specific sequence. The first person (person i) with the sword executes the person that is next in the circle (person i + 1) passing on the sword to the next person alive. This continues to go-on until only one person remains”.

This one described above is a special case of the Josephus Problem. The more general case would be where the number of people is ‘n’ and the sword is passed on from (k – 2)th to the kth person after killing the (k – 1)th person. We will look at few general cases of the problem. We will also look at some code on the way with some visuals. The table below is is the sequence of the deaths of 100 people standing in a loop. There is also an animation at the end of the table.

Key: 

  • Each row represents an iteration.
  • 1 and Green – Alive (and possibly healthy)
  • 0 and Red – Dead

The one left alive is 73rd person. An animated version of the problem is shown below.

Code:

  • Here is the PDF  of the Mathematica code

End of the post.


.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.