Sei sulla pagina 1di 26

Margarita Spitakova

presents

Josephus problem
Josephus Flavius returns.
Not alone.
Bloody thriller

Horrible story
We are trapped here,
in cave, blocked by
Romans

Death is better that


capture. Lets form a circle
and start killing each other
with step two.

Josephus is
my friend
Hmm.. lets
count
I dont
want to
die..

Who will survive???


Why
me???

10
9
8

We will kill
every second
man

3
4
5

Who will survive???

10

2
3

8
7

5
Just
try

Who will survive???

10

2
3

8
7

Oops

Who will survive???

10

2
3

8
7

I knew it

Who will survive???

Do it fast

10

2
3

8
7

Who will survive???


Please
dont kill
me

10

2
3

8
7

Who will survive???

10

2
3

8
7

Oooh, no!

Who will survive???

10

2
3

9
Im alive

8
7

Who will survive???

I(10)=9
Josephus
friend

10

2
3

8
7

5
J(10)=5
Josephus

Problem statement
Josephus problem: For n people, who stands
in circle, find the position of the survivor
J(n), if we will kill every second man.
Josephus friend problem: For n people, who
stands in circle, find the next-to-last position
of the penultimate survivor I(n), if we will
kill every second man.

Lets make more executions!!!!


1

K8
K4
K2

Lets make more executions!!!!


K8=2K4-1

1
2
4

K8

K4

K2

3
2

5
3

7
4

Lets make more executions!!!!


K8=2K4-1

1
2
4

K8

K4

K2

3
2

5
3

7
4

Lets make more executions!!!!


K8=2K4-1

1
K2=1 => J

K4=2K2-1
K8=2K4-1=2(2K2-1)-1=4K2-3

K2=2 => I
2

J(8)=4*1-3=1
I(8)=4*2-3=5

K8

K4

K2

3
2

5
3
2

7
4

Lets make more executions!!!!


K8=2K4-1

1
K2=1 => J
K2=2 => I
2

K4=2K2-1
K8=2K4-1=2(2K2-1)-1=4K2-3
J(8)=4*1-3=1
I(8)=4*2-3=5

Lets generalize: if 2n
J(2n)=J(n)-1, J(1)=1
I(2n)=I(n)-1, I(2)=2

More deaths!!!!
K5

1
5
4

2
3

K2

More deaths!!!!
K5

K2

2
1

K5=2K2+1
J(5)=2*1+1=3
I(5)=2*2+1=5

Lets generalize: if (2n+1)


J(2n+1)=J(n)+1, J(1)=1
I(2n+1)=I(n)+1, I(2)=2

3
1

5
2

K2=1 => J
K2=2 => I

Weve found recurrent formula


Josephus number:
J(1)=1
J(2n)=J(n)-1
J(2n+1)=J(n)+1
Josephus friend number:
I(2)=2
I(2n)=I(n)-1
I(2n+1)=I(n)+1

Lets find the closed form


21+20
21
n

22+21
23

22

23+22

24

10 11 12 13 14 15 16 17 18 19 20

J(n) 1

I(n)

11 1

11 13 15 1

11 13 15 17

J(2m+k)=2k+1, 0k<2m
I will guess that
sequence

I(2m+2m-1+k)=2k+1,
0k<2m+2m-1

Josephus number:
Lets prove it
J(2m+k)=2k+1, 0k<2m
J(2n)=J(n)-1
J(2n+1)=J(n)+1

J(2n+1)-J(2n)=2

Basis. m=0.
k=0. J(20+0)=J(1)=1
Step.
2n=2m+k. k is even
J(2m+k)=2J(2m-1+k/2)-1=2(2*k/2+1)-1=2k+1;
2n+1=2m+k. k is odd
One way:(k=h+1)
J(2m+h+1)=2J(2m-1
+h/2)+1=2(2*h/2+1)+1=2h+2+1=2(h+1)+1=2k+1;
Another way:
J(2n+1)=2+J(2n)=2+2k+1=2(k+1)+1

Josephus friend number:


Lets prove it
I(2m+2m-1+k)=2k+1,0k<2m+2m-1
I(2n)=I(n)-1
I(2n+1)=I(n)+1
Basis. m=1.
k=0. I(21+20+0)=I(3)=1
k=1. I(21+20+1)=I(4)=3
k=2. I(21+20+2)=I(5)=5
Step.
2n=2m+2m-1+k. k is even
I(2m+2m-1+k)=2I(2m-1+2m-2+k/2)-1=2(2*k/2+1)-1=2k+1;
2n+1=2m+2m-1+k. k is odd (k=h+1)
I(2m+2m-1+h+1)=2I(2m-1+2m-2
+h/2)+1=2(2*h/2+1)+1=2h+2+1=2(h+1)+1=2k+1;

Some observations
21+20
21
n

22+21
23

22

23+22

24

10 11 12 13 14 15 16 17 18 19 20

J(n) 1

I(n)

+1

-2

+2

+2

-4

-4

+4

+4

+4

11 13 15 1

11 1

11 13 15 17

+4

-8

-8

-8

+8

+8

-8

I dont believe

I(n)=J(n)+2m-1, k<2m-1
I(n)=J(n)-2m, 2m-1k<2m

+8

+8

+8

Can we show it?


I(n)=J(n)+2m-1, k<2m-1
I(n)=J(n)-2m, 2m-1k<2m

I(2m+2m-1+k)=2k+1,0k<2m+2m-1
J(2m+k)=2k+1, 0k<2m

n=2m+k
0 k-2m-1 and

k<2m >>> 2m-1k<2m

I(2m+2m-1+k-2m-1)=2(k-2m-1)+1=2k+1-2m=J(2m+k)-2m
0k+2m-2<2m-1+2m-2

>>> k<2m-1

I(2m-1+2m-2+k+2m-2)=2(k+2m+2)+1=2k+1+2m+2=J(2m+k)+2m-1

Happy
End
Lets thank http://bad-blood.deviantart.com/ for smiley's

Potrebbero piacerti anche