Variants of the Josephus Problem.

Daisuke  Minematsu (Osaka University, Osaka Japan), Hiroshi  Matsui ( Kwanseigakuin High School, Nishinomiya City Japan), Toshiyuki  Yamauchi (Kwanseigakuin High School), Soh  Tatsumi (Kwanseigakuin High School), Masakazu  Naito (Kwanseigakuin High School) and Takafumi  Inoue (Kwanseigakuin High School).

Initialization Code

joseprocess[m_,mm_]:=Block[{t,p,q,u,v,w},proc1={};proc2={};w=mm;
t=Range[m];
p=t;
q=t;
Do[p=RotateLeft[p,w];
u=First[p];proc1=Append[proc1,u];
p=Rest[p];
q=Drop[q,Position[q,u][[1]]];
If[Length[p]==1,Break[],];
q=RotateRight[q,w];
v=Last[q];proc2=Append[proc2,v];
q=Drop[q,-1];
p=Drop[p,Position[p,v][[1]]];
If[Length[q]==1,Break[],],{n,1,Ceiling[m/2]}];{proc1,proc2}];
pic2[num_,poin1_List,poin2_List]:=Block[{},ar=4;
dai=1.5;
haba=0.15;
points=Table[m,{m,1,num}];
points1=poin1;
points2=poin2;
compoint=Complement[points,Union[points1,points2]];
pt=Length[compoint];
survivepoints=compoint;Graphics[Evaluate[{{GrayLevel[1],Rectangle[{4dai-haba-4,dai/2-haba-2.5},{4dai+haba-4,dai/2+haba-2.5}]},{GrayLevel[1],Rectangle[{4dai-haba-8,dai/2-haba+0.8},{4dai+haba-8,dai/2+haba+0.8}]},Table[{GrayLevel[0.8],Disk[{dai*Cos[(ar+points1[[n]])*Pi*(2/num)],dai*Sin[(ar+points1[[n]])*Pi*(2/num)]},haba]},{n,1,Length[points1]}],Table[{GrayLevel[0.8],Rectangle[{dai*Cos[(ar+points2[[n]])*Pi*(2/num)]-haba,dai*Sin[(ar+points2[[n]])*Pi*(2/num)]-haba},{dai*Cos[(ar+points2[[n]])*Pi*(2/num)]+haba,dai*Sin[(ar+points2[[n]])*Pi*(2/num)]+haba}]},{n,1,Length[points2]}],Table[{GrayLevel[0.3],Text[points[[n]],{dai*Cos[(ar+points[[n]])*Pi*(2/num)],dai*Sin[(ar+points[[n]])*Pi*(2/num)]}]},{n,1,Length[points]}],{If[pt==1,RGBColor[0,1,1],GrayLevel[0.3]],Text[survivepoints[[1]],{dai*Cos[(ar+survivepoints[[1]])*Pi*(2/num)],dai*Sin[(ar+survivepoints[[1]])*Pi*(2/num)]}]},{If[pt==1,RGBColor[0,1,1],GrayLevel[1]],Circle[{dai*Cos[(ar+survivepoints[[1]])*Pi*(2/num)],dai*Sin[(ar+survivepoints[[1]])*Pi*(2/num)]},haba]}}],ImageSize->{350,350},AspectRatio->Automatic]];
proc[n2_]:=Block[{pp},pp={{0,0},{1,0}};k=1;h=0;Do[h=h+1;pp=Append[pp,{k,h}];k=k+1;pp=Append[pp,{k,h}],{ss,Floor[n2/2-1]}];If[OddQ[n2],h=h+1;pp=Append[pp,{k,h}],];pp];
d1[k_,mm_]:=joseprocess[k,mm][[1]];d2[k_,mm_]:=joseprocess[k,mm][[2]];
gg={{1,1,3,4,3,6,1,3,9,1,11,5,11,7,9,14,5,12,7,12,11,14,9,22,5,20,7,28,3,30,1,11,25,9,27,5,35,7,33,3,41,1,43,5,43,7,41,19,33,17,35,13,43,15,41,27,33,25,35,29,35,31,33,54,13,52,15,52,19,54,17,46,29,44,31,52,27,54,25,46,37,44,39,44,43,46,41,54,37,52,39,60,35,62,33,86,13,84,15,84,19,86,17,78,29,76,31,84,27,86,25,110,5,108,7,108,11,110,9,118,5,116,7,124,3,126,1,43,89,41,91,37,99,39,97,35,105,33,107,37,107,39,105,19,129,17,131,13,139,15,137,27,129,25,131,29,131,31,129,11,153,9,155,5,163,7,161,3,169,1,171,5,171,7,169,19,161,17,163,13,171,15,169,27,161,25,163,29,163,31,161,75,121,73,123,69,131,71,129,67,137,65,139,69,139,71,137,51,161,49,163,45,171,47,169,59,161,57,163,61,163,63,161,107,121,105,123,101,131,103,129,99,137,97,139,101,139,103,137,115,129,113,131,109,139,111,137,123,129,121,131,125,131,127,129,214,45,212,47,212,51,214,49,206,61,204,63,212,59,214,57,206,69,204,71,204,75,206,73,214,69,212,71,220,67,222,65,182,109,180,111,180,115,182,113,174,125,172,127,180,123,182,121,206,101,204,103,204,107,206,105,214,101,212,103,220,99,222,97,182,141,180,143,180,147,182,145,174,157,172,159,180,155,182,153,174,165,172,167,172,171,174,169,182,165,180,167,188,163,190,161,214,141,212,143,212,147,214,145,206,157,204,159,212,155,214,153,238,133,236,135,236,139,238,137,246,133,244,135,252,131,254,129,342,45,340,47,340,51,342,49,334,61,332,63,340,59,342,57,334,69,332,71,332,75,334,73,342,69,340,71,348,67,350,65,310,109,308,111,308,115,310,113,302,125,300,127,308,123,310,121,334,101,332,103,332,107,334,105,342,101,340,103,348,99,350,97,438,13,436,15,436,19,438,17,430,29,428,31,436,27,438,25,430,37,428,39,428,43,430,41,438,37,436,39,444,35,446,33,470,13,468,15,468,19,470,17,462,29,460,31,468,27,470,25,494,5,492,7,492},{1,2,1,2,4,6,2,1,8,2,8,8,9,13,7,15,2,2,1,20,15,7,22,10,18,13,13,16,16,14,10,29,8,21,14,33,8,34,2,40,40,2,2,1,4,43,38,19,36,16,48,5,47,22,37,19,38,26,32,29,29,37,31,34,35,35,40,31,42,51,20,65,13,61,16,60,32,47,31,53,10,72,13,71,16,76,7,87,2,89,5,5,87,7,94,2,4,98,99,1,8,98,10,97,84,23,83,43,70,38,78,34,80,32,108,13,108,10,106,19,108,49,80,44,82,43,88,43,83,47,76,64,72,67,72,64,76,77,64,83,62,75,68,75,73,70,77,74,73,77,90,67,86,68,92,67,97,115,47,118,43,146,22,145,28,132,32,135,35,139,40,133,74,107,77,106,76,111,68,119,67,115,20,163,26,159,29,163,32,157,35,161,29,170,29,183,14,195,8,196,2,195,5,198,11,199,198,10,200,19,198,16,210,5,209,4,217,2,7,217,4,222,222,5,225,1,20,215,16,220,16,213,20,218,22,212,186,49,190,56,186,59,149,95,155,94,166,85,179,77,173,76,181,77,177,76,188,70,243,22,234,28,247,26,246,22,237,32,236,43,232,38,240,107,167,106,180,103,183,97,184,103,196,97,195,91,196,97,196,104,185,107,190,127,171,130,156,142,161,143,156,151,165,145,160,143,168,140,168,168,140,171,143,175,131,184,137,183,140,169,155,172,151,168,161,167,163,155,175,160,172,163,170,164,164,176,167,173,170,140,200,151,196,151,191,155,197,145,207,148,203,149,209,140,104,259,107,255,104,264,100,268,95,316,40,326,49,323,46,324,62,314,64,296,74,307,70,303,80,302,77,307,73,306,89,301,91,297,169,228,158,241,157,223,172,237,163,232,169,231,154,249,152,256,140,265,143,261,158,259,47,370,43,366,53,358,56,361,64,356,65,361,59,364,80,359,73,353,80,354,77,362,76,361,64,379,58,380,65,379,32,409,34,417,32,439,13,433,16,440,14,448,2,451,19,446,11,451,17,444,20,441,23,448,449,23,443,22,451,23,447,40,433,38,445,35,444,34,449,13,475,11,470,17,469,8,483,5,486,2,490,479,16,482,10,486,8,494,10,499},{1,1,3,1,3,5,7,2,5,8,6,2,11,2,15,11,6,14,10,14,10,2,19,6,25,3,26,3,14,18,9,24,15,20,17,23,18,24,38,3,33,14,37,5,43,3,46,6,44,5,49,31,26,30,15,47,18,41,26,36,30,36,29,40,27,38,30,40,67,6,70,3,59,21,54,17,64,14,74,7,79,5,81,6,77,9,79,6,84,6,87,52,42,54,45,52,30,76,25,82,18,74,33,71,46,65,47,60,51,60,51,64,51,70,49,72,42,66,51,68,54,73,119,9,119,5,123,5,129,29,99,35,93,42,91,30,113,27,118,11,129,10,134,7,143,9,145,9,143,9,143,17,141,13,141,25,151,11,147,10,147,11,151,91,73,96,74,91,79,97,82,90,51,128,43,135,41,145,37,152,54,130,58,128,63,125,82,114,78,110,82,106,89,108,89,104,93,112,90,112,90,125,82,122,86,126,83,138,94,117,94,126,90,120,87,123,91,23,211,15,209,17,210,9,220,11,215,7,227,5,183,54,176,63,177,66,164,73,169,82,192,53,195,47,197,46,207,42,233,19,229,25,239,18,237,13,249,7,249,14,253,9,255,17,253,17,255,17,252,35,245,26,252,23,249,30,243,43,265,15,265,19,261,25,271,13,259,19,273,26,118,160,130,168,130,171,131,170,141,160,139,166,134,162,147,160,150,222,90,226,78,240,77,238,73,259,63,257,65,270,53,230,94,230,103,226,98,226,111,221,113,191,145,196,137,202,147,196,149,198,141,186,159,182,157,192,158,188,169,196,163,199,163,198,158,198,158,202,155,227,146,218,150,214,151,213,147,224,141,245,131,208,167,206,165,214,157,224,159,212,171,228,153,218,171,228,162,39,373,19,369,27,371,30,369,26,372,25,387,13,388,19,387,26,393,11,399,9,404,83,325,89,321,106,311,111,308,107,315,115,291,134,295,130,300,129,285,146,340,93,341,90,357,83,355,90,357,81,367,74,371,73,414,31,415,45,406,45,408,29,419,30,421,37,415,19,443,22,450,23,441,25,442,18,455,15,443,19,447,29,453,27,447,27,453,30,451,31,446,62,433,50,438,45,443,42,445,39,443,57,442,61,431,78,422,29,473,26,478,33},{1,2,1,4,1,4,3,1,8,7,4,1,2,6,9,9,12,17,1,1,2,9,17,14,14,13,17,25,6,2,31,32,3,34,25,13,21,21,18,19,25,19,9,39,9,36,47,48,47,49,4,52,6,19,38,18,40,29,28,29,28,35,38,31,37,28,40,61,12,58,14,56,3,6,4,6,72,3,7,79,6,82,9,81,55,31,62,27,62,24,50,52,46,46,43,58,46,44,58,48,59,49,63,44,60,89,18,93,22,89,22,96,31,113,112,8,117,115,113,12,2,4,11,118,6,119,8,125,13,120,12,44,86,48,90,43,97,41,97,49,109,69,77,81,66,78,79,68,66,90,63,85,76,67,89,73,87,69,89,76,98,66,100,71,31,138,24,143,27,139,33,139,36,144,29,133,47,175,6,11,173,4,182,182,11,13,175,17,173,11,190,180,17,184,9,190,14,186,11,195,9,186,21,186,17,195,141,77,134,73,140,78,151,69,153,63,151,72,146,56,170,108,120,108,102,126,102,122,112,112,129,97,103,137,99,141,121,131,117,104,141,107,140,114,134,112,142,112,138,118,135,104,153,104,154,109,145,213,46,227,37,225,44,226,38,215,52,218,56,214,52,225,48,233,71,206,72,273,9,275,273,14,270,18,279,6,9,283,16,267,275,21,272,27,270,296,284,12,296,280,24,280,21,286,13,296,16,290,22,295,17,306,13,307,31,289,34,292,32,297,27,305,221,108,208,122,207,114,219,117,220,113,236,106,234,101,240,97,234,111,234,118,228,87,264,86,182,166,186,168,168,197,163,198,158,184,173,187,191,173,201,166,216,207,159,213,153,217,152,184,169,205,182,196,217,159,219,166,216,167,208,177,210,176,219,168,222,173,216,187,211,178,215,162,235,159,239,163,239,171,234,181,230,334,71,334,57,353,53,348,68,350,64,351,69,334,83,342,82,337,88,334,87,348,77,351,73,362,69,324,114,320,112,428,13,425,13,428,429,26,424,22,421,28,442,13,441,9,13,442,18,432,24,416,428,33,425,37,421,41,421,47,6,24,445,17,462,9,36,434,38,437,32,446,32,436,19,461,22,460,27,454,34,453,29,463,22,477,18,468,17,446,48,452,52,449,44,447,48,464},{1,1,2,3,3,3,3,4,9,10,4,5,12,14,7,15,14,4,16,10,7,16,7,24,22,5,23,11,20,23,11,22,10,30,5,9,30,5,33,13,31,19,9,35,15,32,15,40,10,47,8,13,43,13,53,17,45,17,41,26,39,54,22,50,21,40,28,52,16,56,13,68,10,26,61,16,61,17,75,13,61,22,61,25,59,29,55,37,17,66,31,71,26,68,41,64,23,74,27,82,25,87,21,96,11,98,74,25,93,31,87,26,93,11,99,14,86,28,92,38,90,43,84,41,77,53,78,108,22,93,45,104,35,101,43,98,59,93,56,112,41,109,38,118,35,113,27,127,29,137,26,139,16,51,104,33,133,34,123,39,125,33,132,13,153,28,151,50,136,40,133,51,123,49,129,61,121,56,124,74,113,76,113,71,35,159,56,136,63,134,51,143,52,142,62,141,87,118,70,130,81,160,61,150,56,156,44,169,50,165,35,178,35,175,40,197,27,200,23,202,29,73,149,79,182,41,189,46,177,61,177,57,184,46,189,35,219,22,203,35,217,71,179,56,193,59,189,73,175,76,185,71,168,83,174,91,181,85,156,105,162,107,159,110,167,222,49,229,44,191,80,185,88,192,74,212,77,208,74,205,89,201,98,163,118,168,99,186,115,179,65,231,83,214,75,220,77,237,59,242,71,239,70,259,57,255,49,251,58,258,31,282,38,288,32,288,31,281,216,104,221,112,214,67,258,55,272,70,268,80,253,80,253,82,256,77,275,69,271,50,321,33,316,56,293,49,311,40,252,97,281,81,278,91,275,88,255,107,250,110,265,101,265,98,242,118,250,123,242,116,255,123,225,151,234,147,225,154,227,153,225,146,67,317,68,330,63,282,118,280,129,265,127,280,123,294,103,304,111,302,106,300,113,280,127,288,121,264,179,242,171,242,143,274,152,254,163,256,92,327,128,307,117,308,107,314,112,322,93,344,83,348,100,337,95,340,105,371,81,368,79,375,68,362,83,370,85,408,47,399,53,383,46,412,44,412,45,404,57,153,316,153,304,160,308,98,375,101,388,82,391,89,379,93,365,116,363,125,373,122,367,117,378,111,397,94,393,101,391,70,460,44,450,44,457,81,422,70,449,57},{1,2,2,2,5,2,5,2,5,8,1,3,8,11,2,4,9,13,10,4,21,4,18,13,13,17,6,1,29,5,31,23,21,23,16,24,6,5,3,4,39,6,31,28,28,32,23,32,22,41,46,5,4,8,54,9,56,8,38,38,33,31,26,38,27,41,29,39,9,9,70,71,65,11,73,11,73,9,72,27,32,51,39,40,47,56,43,59,36,55,39,54,23,86,80,9,94,96,5,17,92,8,91,15,98,10,99,13,77,45,37,67,53,52,66,58,47,75,54,78,48,78,54,75,52,79,31,117,115,17,124,9,10,129,5,23,123,13,132,20,126,22,133,11,134,17,133,43,104,60,51,94,67,88,83,73,86,79,58,102,69,94,72,107,64,107,71,97,73,104,76,106,43,145,22,25,159,16,171,11,5,177,12,183,160,24,169,18,179,15,169,25,169,25,180,15,183,22,182,27,194,55,140,81,79,142,83,122,94,118,112,97,120,103,114,143,85,138,87,117,97,129,85,142,85,146,97,135,103,137,94,141,102,145,55,185,44,214,213,44,216,24,229,17,235,246,16,239,16,245,6,40,220,33,229,24,253,20,243,34,233,33,228,36,246,24,252,20,246,30,248,22,245,8,204,89,169,109,108,192,99,175,122,165,128,160,149,129,158,131,162,141,153,194,106,187,115,185,127,160,131,174,114,197,116,192,111,196,132,186,131,177,132,190,127,190,138,201,130,249,76,265,61,291,40,43,273,53,294,27,310,22,318,18,5,319,19,324,22,335,10,340,293,52,307,44,311,40,323,11,329,26,331,46,308,47,317,52,312,44,333,39,334,24,343,31,332,37,338,29,327,41,366,106,274,120,260,150,236,239,142,261,150,239,165,222,165,218,176,215,201,176,218,181,223,179,211,192,207,263,143,259,153,254,159,250,173,215,181,238,179,237,157,266,163,261,160,271,153,262,178,253,180,244,190,244,181,259,172,259,174,250,164,265,198,338,103,360,83,362,50,392,392,58,368,80,398,54,413,36,421,30,430,26,437,454,9,433,25,441,29,440,13,455,13,464,399,72,406,57,415,58,421,53,439,12,448,36,449,34,448,62,419,58,427,59,426,73,423,60,454,46,446,44,466,31,466,39,453,54},{1,1,3,1,4,3,5,3,5,4,10,11,4,4,12,13,5,6,16,19,10,21,19,5,20,13,10,19,7,11,27,5,24,17,13,26,19,35,5,10,37,5,32,17,11,35,18,30,13,46,6,17,45,11,54,18,39,27,13,44,19,43,29,53,11,57,6,22,58,14,63,7,55,29,50,34,17,64,26,56,30,50,41,68,14,74,10,29,65,20,73,18,81,7,94,29,64,38,62,46,20,83,34,78,38,72,46,64,50,88,17,100,23,108,82,36,98,25,95,21,105,18,120,6,92,38,83,50,91,55,77,112,29,96,44,101,49,95,51,86,65,78,33,116,22,130,27,137,13,144,105,47,127,33,125,38,136,27,138,18,155,7,157,51,120,63,108,58,118,70,101,142,31,141,57,126,55,132,63,123,65,122,76,104,87,104,42,148,30,168,27,163,38,181,19,188,138,62,143,39,164,41,158,49,176,37,178,35,191,11,198,7,205,68,159,78,141,83,141,75,153,91,133,102,46,191,49,182,70,164,74,173,65,158,77,158,86,158,98,133,109,132,113,194,51,196,39,216,35,222,44,208,26,230,23,245,181,86,185,79,217,55,213,52,207,62,223,44,226,42,234,44,249,26,265,21,274,14,203,86,206,91,184,107,183,109,194,93,173,118,170,127,167,240,54,238,61,237,97,212,93,211,84,223,79,206,100,209,110,203,110,189,131,173,141,175,150,177,71,259,75,256,50,282,44,285,44,276,63,272,27,299,31,313,22,106,230,103,242,103,283,73,278,70,283,75,272,82,290,57,290,62,305,54,302,50,324,34,347,23,348,10,350,23,263,111,269,108,243,137,237,140,236,140,253,121,261,156,231,162,224,166,217,314,73,324,82,314,84,268,117,276,121,276,119,292,110,293,131,266,131,274,141,267,146,269,151,247,170,224,183,242,190,218,191,235,92,338,97,334,91,362,60,371,58,370,57,370,74,354,82,395,46,389,41,409,26,413,306,141,296,132,314,133,320,83,357,91,360,87,368,98,349,106,354,83,384,73,382,79,397,74,398,75,405,47,425,43,453,28,436,23,465,21,455,134,343,146,350,141,347,171,311,177,309,182,314,183,320,165,331,156,340,203,300,196,297,211,288,221},{1,2,1,4,1,1,1,8,1,8,10,11,8,7,1,16,10,8,2,20,12,8,20,5,11,23,13,8,24,4,1,25,10,22,19,10,31,5,3,31,10,36,22,24,39,20,38,45,48,4,19,45,15,23,26,31,50,15,49,21,11,7,2,53,25,55,19,54,34,43,38,23,66,31,61,26,13,6,75,3,20,59,29,68,23,68,59,51,39,49,72,20,74,32,77,30,76,87,97,11,2,5,25,73,32,87,32,88,30,42,53,67,47,62,57,35,99,30,85,28,92,41,95,109,122,12,118,3,128,106,42,85,40,112,41,105,32,106,91,52,66,84,60,76,75,38,109,31,129,31,108,35,117,47,110,41,24,10,153,13,148,4,3,7,38,119,58,127,55,140,51,133,39,145,47,67,117,99,82,105,76,91,92,102,144,55,154,34,147,38,134,53,154,50,141,64,151,175,32,13,195,19,192,23,1,5,202,157,47,150,68,140,59,150,42,168,65,167,49,182,46,170,145,82,103,125,104,132,96,144,116,121,110,59,171,41,195,43,205,57,199,79,182,53,184,67,178,80,191,67,37,219,247,13,244,22,243,28,6,5,261,12,260,210,60,189,85,182,95,200,88,224,59,198,82,211,68,223,55,213,71,106,182,104,129,158,130,169,128,176,114,150,147,150,139,158,215,86,242,59,247,46,235,71,251,98,219,83,249,76,237,92,227,101,239,80,248,279,48,275,308,15,308,28,309,32,297,327,329,6,5,15,328,250,74,264,103,236,113,220,93,251,111,284,69,278,103,249,86,265,77,280,66,286,93,272,228,134,233,129,164,199,166,206,159,211,151,224,192,192,185,192,176,203,137,110,272,107,306,75,313,50,327,94,302,74,267,123,277,104,314,91,296,100,284,116,273,124,303,101,302,351,57,350,62,24,392,17,388,37,386,29,376,44,8,4,417,8,6,17,415,62,93,336,95,302,134,298,143,268,151,322,122,301,50,357,86,352,109,313,123,340,113,342,95,352,83,362,115,339,112,170,290,168,297,163,208,253,215,258,194,267,205,272,190,282,242,239,233,243,235,238,222,252,362,139,344,138,404,100,391,93,401,73,412,119,381,95,401,159,341,148,351,130,396,107,370,128,375,146}};
jLintersection[n_,rs_] := Block[{p, q,u},elim={};elim2={};p = Join[Range[n],Sort[Table[m,{m,2,n-1}],Greater]];
q = Reverse[Join[Reverse[Range[n]],Table[k,{k,2,n-1}]]];
   Do[Do[u1=First[p];
u2=First[RotateLeft[p,1]];
If[u1==u2,p=RotateLeft[p,2],p=RotateLeft[p,1]],{s,1,rs}];
    u = First[p];
    p = Rest[p];elim=Append[elim,u];If[MemberQ[p,u],p=Delete[p,Position[p,u]],];
If[MemberQ[q,u],q=Delete[q,Position[q,u]],];
If[Length[p]==1,Break[],];
Do[u1=Last[q];
u2=Last[RotateRight[q,1]];
If[u1==u2,q=RotateRight[q,2],q=RotateRight[q,1]],{s,1,rs}];
    u = Last[q];
    q = Drop[q,-1];elim2=Append[elim2,u];
If[MemberQ[q,u],q=Delete[q,Position[q,u]],];If[MemberQ[p,u],p=Delete[p,Position[p,u]],];If[Length[q]==1,Break[],], {t, 1, Ceiling[n/2]}];
{elim,elim2}];
gr2[m_,x_List,y_List]:=Block[{num=m},la=Complement[Range[num],x,y];haba=0.5;pp=Table[nn,{nn,1,num}];qq=x;rr=y;Show[Graphics[Evaluate[{{GrayLevel[1],Disk[{num+1,1},0.4]},{GrayLevel[1],Disk[{0,1},0.4]},Table[{GrayLevel[0.9],Disk[{qq[[n]],1},0.4]},{n,1,Length[qq]}],
Table[{GrayLevel[0.2],Disk[{rr[[n]],1},0.4]},{n,1,Length[rr]}],{If[Length[la]==1,Hue[0.4],RGBColor[1,1,1]],Circle[{la[[1]],1},0.4]},Table[{GrayLevel[0.6],Text[pp[[n]],{pp[[n]],1}]},{n,1,Length[pp]}]}],ImageSize->{400,300}]]];proc[n2_]:=Block[{pp},pp={{0,0},{1,0}};k=1;h=0;Do[h=h+1;pp=Append[pp,{k,h}];k=k+1;pp=Append[pp,{k,h}],{ss,Floor[n2/2-1]}];If[OddQ[n2],h=h+1;pp=Append[pp,{k,h}],];pp];
d12[k_,r_]:=jLintersection[k,r][[1]];d22[k_,r_]:=jLintersection[k,r][[2]];

Section 1.  Introduction and the traditional Josephus Problem.

According to legend, Josephus was the leader of a group of Jewish rebels who were trapped by the Romans.His subordinates preferred suicide to surrender, so they decided to form a circle and eliminate every other member until no one was left.Josephus wanted to live, so he calculated where to stand and managed to be the last member.If there were n numbers, where did Josephus stand? We denote by J (n) the position of the survivor.

The Josephus function J(n) has the following recursive relations. 
J (2 m) = 2 J (m) - 1
J (2 m + 1) = 2 J (m) + 1
These are well known recursive relation.

Section 2.  A Josephus problem with an intersection.

In this variant of the Josephus Problem two numbers are to be eliminated at the same time, but two processes of elimination go for different directions. Let n and k be natural numbers.  Suppose that there are n-numbers.Then the ﬁrst process of elimination starts with the 1 st number and the k-th, 2k-th, 3k-th number, ... are to be eliminated.The second process starts with the n - th number, and the (n − k+1) - th, (n − 2k+1) - th, (n-3k+1)th  number, ... are to be eliminated.We suppose that the ﬁrst process comes ﬁrst and the second process second at every stage. We denote the position of the survivor by JI (n,k).

Example.  This is a Mathematica function to calculate JI (n,k).  It is based on a very simple algorithm.  You can calculate  JI (n,k)  by  JI[n,k].

JI[m_,mm_]:=Block[{t,p,q,u,v,w,pp},If[m>1,w=mm-1;
t=Range[m];
p=t;
q=t;
Do[p=RotateLeft[p,w];
u=First[p];
p=Rest[p];
q=Drop[q,Position[q,u][[1]]];
If[Length[p]==1,Break[],];
q=RotateRight[q,w];
v=Last[q];
q=Drop[q,-1];
p=Drop[p,Position[p,v][[1]]];
If[Length[q]==1,Break[],],{n,1,Ceiling[m/2]}];pp=p[[1]],pp=1];pp];

Example.   Here we can show how to use JI (n,k).

JI[256,2]

By the above calcualtion we know the following fact.
If we put 256 person in a circle and we eliminate every 2nd person in the Josephus Problem with an intersection, then the 214th person will be the survivor.

Example.  This is a Mathematica Demonstration to show how to eliminate numbers in the Josephus problems with intersection. Note that the number of steps should not be bigger than the number of numbers.
If you choose "demo", you can see how to eliminate numbers.
If you choose "graph", you can see the graphs of these variants. 
The horizontal coordinate is for the number of number involved in the game, and the vertical coordinate is for the position of the last number remains. For example by  JI(256,2) = 214 we have the point (256, 214) in the graph for k = 2.

Remark. If the following Demonstration does not work properly, please activate Initialization Codes at the beginning of this article.

Manipulate[
If[hh>nn,hh=nn];
Which[se==20,
pic2[nn,Table[d1[nn,mm-1][[s]],{s,1,proc[nn][[hh,1]]}],Table[d2[nn,mm-1][[u]],{u,1,proc[nn][[hh,2]]}]],
se==1000,
ListPlot[gg[[mm-1]],PlotRange->{{0,500},{0,500}},ImageSize->{350,350}]],{{se,20,""},{20->"demo",1000->"graph"},ImageSize->Tiny},
{{nn,8,"number of players n"},2,20,1,Enabled->se===20,Appearance->"Labeled",ImageSize->Tiny},
{{hh,4,"steps (half-stages)"},1,nn,1,Enabled->se===20,Appearance->"Labeled",ImageSize->Tiny},
{{mm,2,"k th"},2,9,1,Enabled->se===20,Appearance->"Labeled",ImageSize->Tiny},
ControlPlacement->Left]

Example.  This is the codes of the AVA applet to show how we eliminate numbers in the Josephus problems with intersection.

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class crossjose_x extends Applet 
	implements ActionListener
{
	double S,C,S2,C2;
	Button b_con=new Button("go forward");
	Button b_uncon=new Button("go back");
	int L;
	int R;
	int k=0;

	private TextField box=new TextField(5);
	private Label moji=new Label("the number of the players　");

	private TextField box2=new TextField(5);
	private Label moji2=new Label("every k th　");

	private Button ok=new Button("OK");

	public void init()
	{

		add(b_con);	add(b_uncon);
		b_con.addActionListener(this);
		b_uncon.addActionListener(this);

		resize(600,600);
		
		add(box);
		add(moji);

		add(box2);
		add(moji2);

		add(ok);
		ok.addActionListener(this);
	}

	public void actionPerformed(ActionEvent e)
	{
		String t=box.getText();
		String t2=box2.getText();
		String s=e.getActionCommand();
		if(s=="go forward")
		{
			if(k<L-1) ++k;
			repaint();
		}
		else if(s=="go back")
		{
			if(1<=k) --k;
			repaint();
		}
		else if(s=="OK")
		{
			L=Integer.parseInt(t);
			R=Integer.parseInt(t2);
			if(L<=R)	R=1;
			k=0;
			repaint();
		}
	}

	public void paint(Graphics g)
	{
		for(int i=1;i<=L;i++)
		{
			S=Math.sin(2*Math.PI/L*i)*L*5;
			C=Math.cos(2*Math.PI/L*i)*L*5;

			String M=Integer.toString(i);
			g.drawString(M,L*10+(int)S, L*10+(int)C);
		}


		int[] p;
		p=new int[L];

		for(int s=0;s<=L-1;s++)
		{
			p[s]=1;
		}
		

		int Ac1=0;
		int Ac2;
		int Bc1=L-1;
		int Bc2;

		for(int F=1;F<=k;F++)
		{
		int con=0;
			if(F%2==1)
			{
				for(;Ac1<=L;Ac1++)
				{
					if(con==R)	break;
					if(p[Ac1]==1 && Ac1<=L-2)
					{
						con=con+1;
						continue;
					}
					if(p[Ac1]==1 && Ac1==L-1)
					{
						Ac1=-1;
						con=con+1;
						continue;
					}
					if(p[Ac1]==0 && Ac1==L-1)	Ac1=-1;					}


				for(Ac2=Ac1;Ac2<=L-1;Ac2++)
				{
					if(p[Ac2]==1)
					{
						p[Ac2]=0;
						break;	
					}

					if(Ac2==L-1)	Ac2=-1;
				}


				if(Ac2<=L-2)	Ac1=Ac2+1;
				if(Ac2==L-1)	Ac1=0;

				g.setColor(Color.black);
				S2=Math.sin(2*Math.PI/L*(Ac2+1))*L*5;
				C2=Math.cos(2*Math.PI/L*(Ac2+1))*L*5;

				g.fillOval(L*10+(int)S2-3, L*10+(int)C2-15, 18, 18);


				if(k==L-1)
				{
					int w=0;
					for(;w<=L-1;w++)
					{
						if(p[w]==1)	break;
					}

					S=Math.sin(2*Math.PI/L*(w+1))*L*5;
					C=Math.cos(2*Math.PI/L*(w+1))*L*5;
			
					g.setColor(Color.red);
					String N=Integer.toString(w+1);
					g.drawString(N,L*10+(int)S, L*10+(int)C);			
				}


			}



			if(F%2==0)
			{
				for(;Bc1>=0;Bc1--)
				{
					if(con==R)	break;
					if(p[Bc1]==1 && Bc1>=1)
					{
						con=con+1;
						continue;
					}
					if(p[Bc1]==1 && Bc1==0)
					{
						Bc1=L;
						con=con+1;
						continue;
					}
					if(p[Bc1]==0 && Bc1==0)	Bc1=L;
				}

				for(Bc2=Bc1;Bc2>=0;Bc2--)
				{
					if(p[Bc2]==1)
					{
						p[Bc2]=0;
						break;	
					}

					if(Bc2==0)	Bc2=L;
				}

				if(Bc2>=1)	Bc1=Bc2-1;
				if(Bc2==0)	Bc1=L-1;

				g.setColor(Color.blue);
				S2=-Math.sin(2*Math.PI/L*(L-Bc2-1))*L*5;
				C2=Math.cos(2*Math.PI/L*(L-Bc2-1))*L*5;

				g.fillOval(L*10+(int)S2-3, L*10+(int)C2-15, 18, 18);

				if(k==L-1)
				{
					int w=0;
					for(;w<=L-1;w++)
					{
						if(p[w]==1)	break;
					}
		
					S=-Math.sin(2*Math.PI/L*(L-w-1))*L*5;
					C=Math.cos(2*Math.PI/L*(L-w-1))*L*5;
		
					g.setColor(Color.red);
					String N=Integer.toString(w+1);
					g.drawString(N,L*10+(int)S, L*10+(int)C);			
				}

			}
			
		}
		
	}
	
}

Remark. JI (n,k)  has an interesting recursive relation when k = 2.  We denot JI(n,k)   by    JI(n).

Theorem A. The recursive relations for JI(n).

(1) JI[8 n] = 4 JI[2 n] - 1 -  Floor[ JI[2 n]/(n + 1) ]
(2)  JI[8 n + 1] = 8 n + 5 - 4 JI[2 n]
(3)  JI[8 n + 2] = 4 JI[2 n] - 3 - Floor[JI[2 n]/(n + 2) ]
(4)  JI[8 n + 3] = 8 n + 7 - 4 JI[2 n].
(5)  JI[8 n + 4] = 8 n + 8 - 4 JI[2 n + 1] + Floor[JI[2 n + 1]/(n + 2) ]
(6)  JI[8 n + 5] = 4 JI[2 n + 1] - 1.
(7)  JI[8 n + 6] = 8 n + 10 - 4 JI[2 n + 1] + Floor[JI[2 n + 1]/(n + 2) ]
(8)  JI[8 n + 7] = 4 JI[2 n + 1] - 3.

Example.  A Mathematica JIR[n]   function to calculate JI(n) that is based on the recursive relations in Theorem A.

JIR[1]=1;JIR[2]=1;JIR[3]=3;JIR[4]=4;JIR[m_]:=JIR[m]=Block[{n,h},h=Mod[m,8];n=(m-h)/8;Which[h==0,4JIR[2n] - 1 - Floor[JIR[2n]/(n+1)],h==1,8n+5-4JIR[2n],h==2, 4JIR[2n]-3-Floor[JIR[2 n]/(n + 2)],h==3,8n+7-4JIR[2n],h==4,8n+8-4JIR[2n+1]+Floor[JIR[2n+1]/(n+2)],h==5,4JIR[2n+1]-1,h==6,8n+10-4JIR[2n+1]+Floor[JIR[2n+1]/(n+2)],h==7,4JIR[2n+1]-3]]

Mathematica calculation to prove Theorem A.  Here we are going to compare  two Mathematica functions  JIR[n]  and  JI[n,k]. 
By using the above two Mathematica functions we can get the following result. It took me 90 seconds to calculate aa.
When we know that two list {JI[m,2], m = 1,2,...500} and   {JIR[m], m = 1,2,...500}  are identical, we can be sure that the recursive relations in the above theorem is correct.

aa=Table[JI[m,2],{m,1,500}]

aa2 = Table[JIR[m], {m, 1, 500}]

Union[aa-aa2]

We have the following conjecture for the function JI (m).

Example.   The function JI(m) has the following remarkable property. As to the concrete data of the conjecture, see the following calculation by Mathematica function JIR[n].

Mod[2,JI(m)]={ ({{0,  if m is even and (2^(2n))≤m<(2^(2n+1))}, {1, otherwise}})

Table[Mod[JIR[n],2],{n,1 ,256}]

Example.  We calculated JI(n) using C++ program, and we found out that Conjecture is correct for n = 1,2,...100000.  The following is the C++ codes for the calculation.

#include <iostream> 
#include <vector>
using namespace std;

int naitoucheck(int player);

int main(void) {
  int interbal=1, player=2, endplayer=1000000, times;
  vector<bool> players;
  
  while(player <= endplayer) {
    players.assign(player,true);
    times=0;
    int right=player-1, left=0, counter=0;

    while(times < player-1) {
      if(times%2==0) {
        if(left > player-1) left=0;
        if(players[left]==true) counter++;
        if(counter <= interbal) {left++; continue;}
        players[left] = false; counter=0; left++;
      } else {
        if(right < 0) right=player-1;
        if(players[right]==true) counter++;
        if(counter <= interbal) {right--; continue;}
        players[right] = false; counter=0; right--;
      }
      times++;
    }
    int i;
    for(i=0; i<player; i++) {
      if(players[i]==true) { 
      break;
      }
    }
    cout << "\r" << player << "-th checking now.";
    if((i+1)%2!=naitoucheck(player)) cout << "\r" << player <<
      " in the ...th trial we got an exception." << endl;
    player++;
  }
  cout << "\n Finish Confirm." << endl;
  return 0;
}

int naitoucheck(int player) {
  if(player%2==1) return 1;

  int sikii=4;
  for(int i=2; i<32; i++) {
    if(i%2==0 && player<sikii) {return 1;}
    if(i%2==1 && player<sikii) {return 0;}
    sikii=sikii*2;
  }
  return 1;
}

Section 3.  Linear Josephus Problems with an intersection.

This is another variant of the Josephus problem.Let n and k be natural numbers.  We put n numbers on a line.Two numbers are to be eliminated at the same time, but two processes of elimination go for different directions.Then the ﬁrst process of elimination starts with the 1 st number and the k nd, 2k th number, ... are to be eliminated.The second process starts with the n - th number, and the (n − k+1) - th, (n − 2k+1) - th number, ... are to be eliminated.We suppose that the ﬁrst process comes ﬁrst and the second process second at every stage.We change the direction when we reach the end of the line.Then we begin removing every second number again.We denote the position of the last number that remains by JLI(n,k).

Example.  This is a Mathematica function to calculate JLI(n,k).  It is based on a very simple algorithm.  You can calculate  JLI(n,k)  by  JLI[n,k].

JLI[n_,mm_]:=Block[{p,q,u,pp,rs},rs=mm-1;If[n>1,p=Join[Range[n],Sort[Table[m,{m,2,n-1}],Greater]];
q=Reverse[Join[Reverse[Range[n]],Table[k,{k,2,n-1}]]];
Do[Do[u1=First[p];
u2=First[RotateLeft[p,1]];
If[u1==u2,p=RotateLeft[p,2],p=RotateLeft[p,1]],{s,1,rs}];
u=First[p];
p=Rest[p];
If[MemberQ[p,u],p=Delete[p,Position[p,u]],];
If[MemberQ[q,u],q=Delete[q,Position[q,u]],];
If[Length[Union[p]]==1,Break[],];
Do[u1=Last[q];
u2=Last[RotateRight[q,1]];
If[u1==u2,q=RotateRight[q,2],q=RotateRight[q,1]],{s,1,rs}];
u=Last[q];
q=Drop[q,-1];
If[MemberQ[q,u],q=Delete[q,Position[q,u]],];
If[MemberQ[p,u],p=Delete[p,Position[p,u]],];
If[Length[Union[q]]==1,Break[],],{t,1,Ceiling[n/2]}];
pp=p[[1]],pp=1];pp];

Remark. If the following Demonstration does not work properly, please activate Initialization Codes at the beginning of this article.

Example.   This is a Mathematica Demonstration to show how to eliminate numbers in the Linear Josephus problems with intersection

Manipulate[gr2[nn,Table[d12[nn,rs][[s]],{s,1,proc[nn][[hh+1,1]]}],Table[d22[nn,rs][[u]],{u,1,proc[nn][[hh+1,2]]}]],
{{rs,1," th player"},1,nn,1,ImageSize->Tiny},
{{nn,8,"number of players"},2,20,2,ImageSize->Tiny},{{hh,0,"number of steps"},0,nn-1,1,ImageSize->Tiny},SaveDefinitions->True]

Theorem B. The recursive relations for JLI(n) = JLI(n,2).

(1) JLI(8n) = 8n+2-4JLI(2n)+ Floor[ JLI(2n)/(n+1) ].  
 (2) JLI(8n+1) = 8n+5-4JLI(2n+1). 
 (3) JLI(8n+2) = 4JLI(2n+1)-3-  Floor[ JLI(2n+1)/(n+2) ]. 
 (4) JLI(8n+3) = 8n+7-4JLI(2n+1). 
 (5) JLI(8n+4) =8n+8-4JLI(2n+2)+ Floor[ JLI(2n+2)/(n+2) ]. 
 (6) JLI(8n+5) = 8n+7-4JLI(2n+1). 
 (7) JLI(8n+6) = 8n+10-4JLI(2n+2)+ Floor[ (JLI(2n+2)/(n+2)]. 
 (8) JLI(8n+7) = 4JLI(2n+2)-3.

Example. This is a Mathematica function JLIR[n] for JLI(n) = JLI(n,2) based on the recursive relations in above theorem. Note that the expression of this function is very similar to that of equations in Theorem B.

JLIR[1]=1;JLIR[2]=1;JLIR[3]=3;JLIR[4]=4;
JLIR[5]=3;JLIR[6]=6;JLIR[7]=1;JLIR[8]=6;
JLIR[9]=1;JLIR[10]=8;JLIR[11]=3;JLIR[12]=1;
JLIR[m_]:=JLIR[m]=Block[{n,k},k=Mod[m,8];n=(m-k)/8;
Which[k==0,8 n+2-4 JLIR[2 n]+Floor[JLIR[2 n]/(n+1)],
k==1,8 n+5-4 JLIR[2 n+1],
k==2,4 JLIR[2 n+1]-3-Floor[JLIR[2 n+1]/(n+2)],
k==3,8 n+7-4 JLIR[2 n+1],
k==4,8 n+8-4 JLIR[2 n+2]+Floor[JLIR[2 n+2]/(n+2)],
k==5,8 n+7-4 JLIR[2 n+1],
k==6,8 n+10-4 JLIR[2 n+2]+Floor[JLIR[2 n+2]/(n+2)],
k==7,4 JLIR[2 n+2]-3]]

Mathematica calculation to prove Theorem B.    JLI[m, 2] and JLIR[m] are Mathematica functions for JLI(n) = JLI(n,2). JLIR[m] is based on the recursive relations in Theorem B, and JLI[m, 2] is not. Therefore we can be almost sure that the recursive relations are correct if these functions produce the same values for sufciently many values of m.
By using the above two Mathematica functions we can get the following result. It will take a few minutes to calculate aa3.
When we know that two list {JLI[m,2], m = 1,2,...500} and   {JLIR[m], m = 1,2,...500}  are identical, we can be sure that the recursive relations in Theorem B is correct.

aa3=Table[JIL[m,2],{m,1,500}]

aa4=Table[JILR[m],{m,1,500}]

Union[aa3-aa4]

Acknowledgement. We would like to thank Mr. Harrison Gray and Dr. Ryohei Miyadera for helping us to prepare this article. Mr. Gray checked our English and Dr. Miyadera helped us when we used Mathematica in this article.