Given a group of men arranged in a circle under the edict that every th man will be executed going around the circle until only one remains, find the position in which you should stand in order to be the last survivor (Ball and Coxeter 1987). The list giving the place in the execution sequence of the first, second, etc. man can be given by Josephus[n, m] in the Wolfram Language package Combinatorica` . For example, consider men numbered 1 to 4 such that each second () man is iteratively slaughtered, as illustrated above. As can be seen, the first man is slaughtered 4th, the second man 1st, the third man 3rd, and the fourth man 2nd, so Josephus[4, 2] returns 4, 1, 3, 2.
To obtain the ordered list of men who are consecutively slaughtered, InversePermutation can be applied to the output of Josephus. So, in the above example, InversePermutation[Josephus[4, 2]] returns 2, 4, 3, 1 since the 2nd man is slaughtered first, the 4th man is slaughtered second, the 3rd man is slaughtered third, and the 1st man is slaughtered fourth.
The original Josephus problem consisted of a circle of 41 men with every third man killed (, ), illustrated above, where the outer number indicates the order in which a given man is killed. In order for the lives of the last two men to be spared, they must be placed at positions 31 (last) and 16 (second-to-last). The complete list in order of execution is 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 1, 5, 10, 14, 19, 23, 28, 32, 37, 41, 7, 13, 20, 26, 34, 40, 8, 17, 29, 38, 11, 25, 2, 22, 4, 35, 16, 31.
Another version of the problem considers a circle of two groups (say, "A" and "B") of 15 men each (giving a total of 30 men), with every ninth man cast overboard, illustrated above. To save all the members of the "A" group, the men must be placed at positions 1, 2, 3, 4, 10, 11, 13, 14, 15, 17, 20, 21, 25, 28, 29. Written out explicitly, the order is
(1)
|
This sequence of letters can be remembered with the aid of the mnemonic "From numbers' aid and art, never will fame depart." Consider the vowels only, assign , , , , , and alternately add a number of letters corresponding to a vowel value, so 4A (o), 5B (u), 2A (e), etc. (Mott-Smith 1954, §149, pp. 94 and 209-210; Ball and Coxeter 1987).
If instead every tenth man is thrown overboard, the men from the "A" group must be placed in positions 1, 2, 4, 5, 6, 12, 13, 16, 17, 18, 19, 21, 25, 28, 29. Written out explicitly,
(2)
|
which can be constructed using the Latin mnemonic "Rex paphi cum gente bona dat signa serena" (Ball and Coxeter 1987).
The following array gives the original position of the last survivor out of a group of , 2, ..., if every th man is killed for , 2, ..., :
(3)
|
(OEIS A032434). The survivor for can be given analytically by
(4)
|
where is the floor function and lg is the logarithm to base 2. The first few solutions are therefore 1, 1, 3, 1, 3, 5, 7, 1, 3, 5, 7, 9, 11, 13, 15, 1, ... (OEIS A006257).
The original position of the second-to-last survivor is given in the following table for , 3, ...:
(5)
|
(OEIS A032435).
The original position of the third-to-last survivor is given in the following table for , 4, ...:
(6)
|
(OEIS A032436).
Mott-Smith (1954, §153, pp. 96 and 212) discusses a card game called "Out and Under" in which cards at the top of a deck are alternately discarded and placed at the bottom. This is a Josephus problem with parameter , and Mott-Smith hints at the above closed-form solution.