At Play With J Second-order Josephus

Eugene McDonnell

Every once in a blue moon this column is relatively easy to write. This one almost writes itself. Just a short while ago I received an intriguing message. It forms the bulk of this column. I've just had to change a word here and there and adjust typography as needed. Here's how the message opens:

Date: Fri, 30 Nov 2001 18:32:13 -0800 (PST)

From: Boyko Bantchev <bantchev@math.bas.bg>

To: forum@jsoftware.com

Subject: Second-order Josephus

In a recent posting Eugene McDonnell defined the verb S that gives the survivor number for the Josephus problem (also in Vector 9/2 (1992)):

   S=. 1&|.&.#:

This leads to a "second-order survival problem"; having eliminated S(n), start again from the beginning with the remaining n-1 people, eliminate the one whose ordinal number in the new sequence is S(n-1), then do the same with S(n-2) and so forth until only one is left. What is the number S2(n) of the second-order survivor?

I must confess that my first reaction was somewhat guarded. I wasn't at all sure that this problem would lead to as much in the way of theory as the original Josephus did. For example, the book Concrete Mathematics, by Graham, Knuth, and Patashnik, devotes a full nine pages to Josephus, and gives half a dozen Josephus problems, in section 1.3. However, my mind was open, so I plowed on. Bantchev's message continues:

{{{ ]y=: 1+i.n 1 2 3 4 5 6 7 8 9

1 2 4 5 6 7 8 9 NB. since 3=S 9

2 4 5 6 7 8 9 NB. since 1=S 8

2 4 5 6 7 8 NB. since 7=S 7

2 4 5 6 8 NB. since 5=S 6

2 4 6 8 NB. since 3=S 5

4 6 8 NB. since 1=S 4

4 6 NB. since 3=S 3

6 NB. since 1=S 2 }}}

        6=S2(9)

        >: k+2^<:m

        k<2^<:m

        2^m

{{{ S2 2+i.30 2 2 3 4 4 4 5 6 7 8 8 8 8 8 9 10 11 12 13 14 15 16 16 16 16 16 16 16 16 16 }}}

/Boyko

I studied this message for a while and was confused. Mr. Bantchev gives a formula for S2 which seemed completely different from the immediately preceding formulas. I couldn't reconcile: when

      k<2 ^ <: m, S2(n) is:      

      2 ^ m 

{{{m =: <. 2 ^. n (A)

k =: n - 2 ^ m}}}

{{{Boyko =: monad define n =. y. m =. <. 2 ^. n k =. n - 2 ^ m if.

do.

else.

end. ) }}}

{{{ Boyko"0 [ 2+i.30 2 2 3 4 4 4 5 6 7 8 8 8 8 8 9 10 11 12 13 14 15 16 16 16 16 16 16 16 16 16 (B)}}}

{{{ #:19 1 0 0 1 1}}}

{{{ }.#:19 0 0 1 1}}}

{{{ ({.+.}.)}.#:19 0 1 1}}}

{{{ 1,({.+.}.)}.#:19 1 0 1 1}}}

{{{ #.1,({.+.}.)}.#:19 11}}}

{{{ >:#.1,({.+.}.)}.#:19 12}}}

{{{ q=:2+i.20

+--+


+


+--+ | 2|0 0 0 1 0|0 0 1 0| 2| | 3|0 0 0 1 1|0 0 1 0| 2| | 4|0 0 1 0 0|0 0 1 1| 3| | 5|0 0 1 0 1|0 1 0 0| 4| | 6|0 0 1 1 0|0 1 0 0| 4| | 7|0 0 1 1 1|0 1 0 0| 4| | 8|0 1 0 0 0|0 1 0 1| 5| | 9|0 1 0 0 1|0 1 1 0| 6| |10|0 1 0 1 0|0 1 1 1| 7| |11|0 1 0 1 1|1 0 0 0| 8| |12|0 1 1 0 0|1 0 0 0| 8| |13|0 1 1 0 1|1 0 0 0| 8| |14|0 1 1 1 0|1 0 0 0| 8| |15|0 1 1 1 1|1 0 0 0| 8| |16|1 0 0 0 0|1 0 0 1| 9| |17|1 0 0 0 1|1 0 1 0|10| |18|1 0 0 1 0|1 0 1 1|11| |19|1 0 0 1 1|1 1 0 0|12| |20|1 0 1 0 0|1 1 0 1|13| |21|1 0 1 0 1|1 1 1 0|14| +--+


+


+--+ }}}

I'm guessing that Mr. Bantchev followed a process much like the one I've described just above: finding the values with his algebraic analysis, converting these to binary, and comparing them with the binary form of the arguments. This is now enshrined in Sloane's On-Line Encyclopedia of Integer Sequences as sequence A066997.

I thought I had found an interesting property of (B). I noted the indices (in 2-origin) of the first appearance of a power of two were at indices 2, 5, 11, 23. I checked in the Online Encyclopedia of Integer Sequences and found that it corresponded to sequence A055010. The entry notes that these numbers, written in binary, are of the form a(n) is 10111111. Furthermore, it gave the following formula for a(n):    a(n) = (3*2^n)-1 I sent a message to Henry Bottomley, the author of this entry, and he in his reply alerted me to the existence of sequence A006165, which is: 1 1 2 2 3 4 4 4 5 6 7 8 8 8 8 8 9 10 11 12 13 14 15 16 16 16 16 16 16 ... This should be familiar, as it is the S2 sequence, with two leading 1s. I kicked myself for not having found this on my own, and began to appreciate that Mr. Bantchev might be on to something not completely trivial. The entry for series A006165, gives two recursive formulas, one for odd n, and the other for even:

{{{ a((2*n)+1) = a(n+1)+a(n) (A)

{{{A =: monad define if.

do.

else.

end. )}}}

{{{ (>:i.+/2^i.y.) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

2 4 4 8 8 8 8 16 16 16 16 16 16 16 16}}}

{{{ 2^i.4 1 2 4 8

15

30

1 2 2 3 4 4 4 5 6 7 8 8 8 8 8 9 10 11 12 13 14 15 16 16 16 16 16 16 16 16

30}}}

Trash/Doc/Articles/Play184 (last edited 2008-12-08 10:45:33 by )