Skip to content

jakewilliami/JosephusProblem.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Josephus Problem

Description

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.

Quick Start

julia> using JosephusProblem

julia> josephus_perm(100)
73

Calculation

We calculate the result using the bitwise formulae fi:

formulae

We can see a pattern that emerges which illustrates these formulae nicely:

formulae