Saturday, July 11, 2015

The Josephus Problem

The Josephus Problem
In [2]:
def Josie(n):
    x=range(1,n+1)
    while len(x)>2:
        a=x[:2]
        print x[2],
        c=x[3:]
        x=c+a
    print x
In [3]:
Josie(41)
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]