cp's OEIS Frontend

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.

A382358 Triangle read by rows: T(n,k) is the number of the k-th eliminated person in the variation of the Josephus elimination process for n people, where in each round, the first person is skipped, the second eliminated and the third is skipped.

This page as a plain text file.
%I A382358 #13 Apr 05 2025 23:40:52
%S A382358 1,2,1,2,3,1,2,1,3,4,2,5,4,1,3,2,5,3,1,4,6,2,5,1,6,4,7,3,2,5,8,4,1,7,
%T A382358 3,6,2,5,8,3,7,4,1,6,9,2,5,8,1,6,10,7,4,9,3,2,5,8,11,4,9,3,10,7,1,6,2,
%U A382358 5,8,11,3,7,12,6,1,10,4,9,2,5,8,11,1,6,10,3,9,4,13,7,12
%N A382358 Triangle read by rows: T(n,k) is the number of the k-th eliminated person in the variation of the Josephus elimination process for n people, where in each round, the first person is skipped, the second eliminated and the third is skipped.
%C A382358 This variation of the Josephus problem is related to under-down-under card dealing.
%C A382358 The n-th row has n elements.
%C A382358 In this variation of the Josephus elimination process, the numbers 1 through n are arranged in a circle. A pointer starts at position 1. With each turn, the pointer skip one number, eliminates the next, and skips one more number. The process repeats until no numbers remain. This sequence represents the triangle T(n,k), where n is the number of people in the circle, and T(n,k) is the elimination order of the k-th number in the circle.
%e A382358 Consider 4 people in a circle. In the first round, person 1 is skipped, person 2 is eliminated, and person 3 is skipped. The remaining people are now in order 4,1,3. In the second round, person 4 is skipped, person 1 is eliminated, and person 3 is skipped. The remaining people are in order 4, 3. In the third round, person 3 is eliminated, and in the last round, person 4 is eliminated. Thus, the order of elimination is 2, 1, 3, 4, and this is the fourth row of the triangle.
%e A382358 Triangle begins;
%e A382358   1;
%e A382358   2, 1;
%e A382358   2, 3, 1;
%e A382358   2, 1, 3, 4;
%e A382358   2, 5, 4, 1, 3;
%e A382358   2, 5, 3, 1, 4, 6;
%e A382358   2, 5, 1, 6, 4, 7, 3;
%e A382358   2, 5, 8, 4, 1, 7, 3, 6;
%e A382358   ...
%o A382358 (Python)
%o A382358 def J(n,A):
%o A382358     l=[]
%o A382358     for i in range(n):
%o A382358         l.append(i+1)
%o A382358     index = 0
%o A382358     P=[]
%o A382358     for i in range(n):
%o A382358         index+=A[i]
%o A382358         index=index%len(l)
%o A382358         P.append(l[index])
%o A382358         l.pop(index)
%o A382358     return P
%o A382358 def invPerm(p):
%o A382358     inv = []
%o A382358     for i in range(len(p)):
%o A382358         inv.append(None)
%o A382358     for i in range(len(p)):
%o A382358         inv[p[i]-1]=i+1
%o A382358     return inv
%o A382358 def UDU(n):
%o A382358     return [1] + [2 for i in range(n)]
%o A382358 seq = []
%o A382358 for i in range(1,20):
%o A382358     seq += J(i, UDU(i))
%o A382358 print(", ".join([str(v) for v in seq]))
%o A382358 (Python)
%o A382358 def row(n):
%o A382358     i, J, out = 0, list(range(1, n+1)), []
%o A382358     while len(J) > 1:
%o A382358         i = (i + 1)%len(J)
%o A382358         out.append(J.pop(i))
%o A382358         i = (i + 1)%len(J)
%o A382358     return out + [J[0]]
%o A382358 print([e for n in range(1, 14) for e in row(n)]) # _Michael S. Branicky_, Mar 24 2025
%Y A382358 Cf. A006257, A225381, A321298, A378635, A382354, A382355, A382356.
%K A382358 nonn,tabl
%O A382358 1,2
%A A382358 _Tanya Khovanova_, _Nathan Sheffield_, and the MIT PRIMES STEP junior group, Mar 22 2025