login
Triangle read by rows: T(n,k) is the number of the k-th eliminated person in the Josephus elimination process for n people and a count of 2, 1 <= k <= n.
3

%I #28 Sep 18 2022 12:35:13

%S 1,2,1,2,1,3,2,4,3,1,2,4,1,5,3,2,4,6,3,1,5,2,4,6,1,5,3,7,2,4,6,8,3,7,

%T 5,1,2,4,6,8,1,5,9,7,3,2,4,6,8,10,3,7,1,9,5,2,4,6,8,10,1,5,9,3,11,7,2,

%U 4,6,8,10,12,3,7,11,5,1,9,2,4,6,8,10,12,1,5,9,13,7,3,11,2,4,6,8,10,12,14

%N Triangle read by rows: T(n,k) is the number of the k-th eliminated person in the Josephus elimination process for n people and a count of 2, 1 <= k <= n.

%C In the Josephus elimination process for n and k, the numbers 1 through n are written in a circle. A pointer starts at position 1. Each turn, the pointer skips (k-1) non-eliminated number(s) going around the circle and eliminates the k-th number, until no numbers remain. This sequence represents the triangle J(n, i), where n is the number of people in the circle, i is the turn number, and k is fixed at 2 (every other number is eliminated).

%H <a href="/index/J#Josephus">Index entries for sequences related to the Josephus Problem</a>

%F From _Pontus von Brömssen_, Sep 18 2022: (Start)

%F The terms are uniquely determined by the following recursive formulas:

%F T(n,k) = 2*k if k <= n/2;

%F T(2*n,k) = 2*T(n,k-n)-1 if k > n;

%F T(2*n+1,k) = 2*T(n,k-n-1)+1 if k > n+1;

%F T(2*n+1,n+1) = 1.

%F (End)

%e Triangle begins:

%e 1;

%e 2, 1;

%e 2, 1, 3;

%e 2, 4, 3, 1;

%e 2, 4, 1, 5, 3;

%e 2, 4, 6, 3, 1, 5;

%e 2, 4, 6, 1, 5, 3, 7;

%e 2, 4, 6, 8, 3, 7, 5, 1;

%e 2, 4, 6, 8, 1, 5, 9, 7, 3;

%e 2, 4, 6, 8, 10, 3, 7, 1, 9, 5;

%e 2, 4, 6, 8, 10, 1, 5, 9, 3, 11, 7;

%e 2, 4, 6, 8, 10, 12, 3, 7, 11, 5, 1, 9;

%e 2, 4, 6, 8, 10, 12, 1, 5, 9, 13, 7, 3, 11;

%e ...

%e For n = 5, to get the entries in 5th row from left to right, start with (^1, 2, 3, 4, 5) and the pointer at position 1, indicated by the caret. 1 is skipped and 2 is eliminated to get (1, ^3, 4, 5). (The pointer moves ahead to the next "live" number.) On the next turn, 3 is skipped and 4 is eliminated to get (1, 3, ^5). Then 1, 5, and 3 are eliminated in that order (going through (^3, 5) and (^3)). This gives row 5 of the triangle and entries a(11) through a(15) in this sequence.

%t Table[Rest@ Nest[Append[#1, {Delete[#2, #3 + 1], #2[[#3 + 1]], #3}] & @@ {#, #[[-1, 1]], Mod[#[[-1, -1]] + 1, Length@ #[[-1, 1]]]} &, {{Range@ n, 0, 0}}, n][[All, 2]], {n, 14}] // Flatten (* _Michael De Vlieger_, Nov 13 2018 *)

%o (Python)

%o def A321298(n,k):

%o if 2*k<=n: return 2*k

%o n2,r=divmod(n,2)

%o if r==0: return 2*A321298(n2,k-n2)-1

%o if k==n2+1: return 1

%o return 2*A321298(n2,k-n2-1)+1 # _Pontus von Brömssen_, Sep 18 2022

%Y The right border of this triangle is A006257.

%Y Cf. A032434, A054995, A181281.

%K easy,nonn,tabl

%O 1,2

%A _Zeph L. Turner_, Nov 02 2018

%E Name clarified by _Pontus von Brömssen_, Sep 18 2022