This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.
%I A321298 #40 Jun 09 2025 20:51:23 %S A321298 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 A321298 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 A321298 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 A321298 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 A321298 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 A321298 <a href="/index/J#Josephus">Index entries for sequences related to the Josephus Problem</a> %F A321298 From _Pontus von Brömssen_, Sep 18 2022: (Start) %F A321298 The terms are uniquely determined by the following recursive formulas: %F A321298 T(n,k) = 2*k if k <= n/2; %F A321298 T(2*n,k) = 2*T(n,k-n)-1 if k > n; %F A321298 T(2*n+1,k) = 2*T(n,k-n-1)+1 if k > n+1; %F A321298 T(2*n+1,n+1) = 1. %F A321298 (End) %F A321298 From _Pontus von Brömssen_, Dec 11 2024: (Start) %F A321298 The terms are also uniquely determined by the following recursive formulas: %F A321298 T(1,1) = 1; %F A321298 T(n,1) = 2 if n > 1; %F A321298 T(n,k) = T(n-1,k-1)+2 if k > 1 and T(n-1,k-1) != n-1; %F A321298 T(n,k) = 1 if k > 1 and T(n-1,k-1) = n-1. %F A321298 T(n,A225381(n)) = 1. %F A321298 T(n,A225381(n+1)-1) = n. %F A321298 (End) %e A321298 Triangle begins: %e A321298 1; %e A321298 2, 1; %e A321298 2, 1, 3; %e A321298 2, 4, 3, 1; %e A321298 2, 4, 1, 5, 3; %e A321298 2, 4, 6, 3, 1, 5; %e A321298 2, 4, 6, 1, 5, 3, 7; %e A321298 2, 4, 6, 8, 3, 7, 5, 1; %e A321298 2, 4, 6, 8, 1, 5, 9, 7, 3; %e A321298 2, 4, 6, 8, 10, 3, 7, 1, 9, 5; %e A321298 2, 4, 6, 8, 10, 1, 5, 9, 3, 11, 7; %e A321298 2, 4, 6, 8, 10, 12, 3, 7, 11, 5, 1, 9; %e A321298 2, 4, 6, 8, 10, 12, 1, 5, 9, 13, 7, 3, 11; %e A321298 ... %e A321298 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 A321298 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 A321298 (Python) %o A321298 def A321298(n,k): %o A321298 if 2*k<=n: return 2*k %o A321298 n2,r=divmod(n,2) %o A321298 if r==0: return 2*A321298(n2,k-n2)-1 %o A321298 if k==n2+1: return 1 %o A321298 return 2*A321298(n2,k-n2-1)+1 # _Pontus von Brömssen_, Sep 18 2022 %Y A321298 The right border of this triangle is A006257. %Y A321298 Cf. A032434, A054995, A181281, A225381, A378635 (row permutation inverses). %K A321298 easy,nonn,tabl %O A321298 1,2 %A A321298 _Zeph L. Turner_, Nov 02 2018 %E A321298 Name clarified by _Pontus von Brömssen_, Sep 18 2022