n people numbered from 1 to n stand in a circle. 1 has a sword, kills 2, and passes the sword to 3, who kills 4 and passes the sword to 5, and so on. This is repeated until only one person remains. Which number ≤ n does the survivor have?
You can read more about this problem on Wikipedia.
julia> using JosephusProblem
julia> josephus_perm(100)
73
We calculate the result using the bitwise formulae fi:
We can see a pattern that emerges which illustrates these formulae nicely:
If your research depends on JosephusProblem.jl, please consider giving us a formal citation: citation.bib
.