Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Find the solution of the Josephus problem
ResourceFunction["JosephusPermutation"][n,m] generates the inverse of the permutation defined by executing every mth member in a circle of n members. |
In a circle of four men in which every second man is iteratively slaughtered, the second man is executed first, the fourth man second, then the third man, and the first man last:
In[1]:= | ![]() |
Out[1]= | ![]() |
The ordered list of men consecutively slaughtered:
In[2]:= | ![]() |
Out[2]= | ![]() |
For n members, the position of the last survivor is the position of the value n:
In[3]:= | ![]() |
In[4]:= | ![]() |
Out[4]= | ![]() |
In[5]:= | ![]() |
Out[5]= | ![]() |
The position of the second-to-last survivor:
In[6]:= | ![]() |
Out[6]= | ![]() |
This work is licensed under a Creative Commons Attribution 4.0 International License