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.

Showing 1-3 of 3 results.

A382354 Triangle T(n,k) read by rows, where row n is a permutation of the numbers 1 through n, such that if a deck of n cards is prepared in this order, and under-down-under dealing is used, then the resulting cards will be dealt in increasing order.

Original entry on oeis.org

1, 2, 1, 3, 1, 2, 2, 1, 3, 4, 4, 1, 5, 3, 2, 4, 1, 3, 5, 2, 6, 3, 1, 7, 5, 2, 4, 6, 5, 1, 7, 4, 2, 8, 6, 3, 7, 1, 4, 6, 2, 8, 5, 3, 9, 4, 1, 10, 8, 2, 5, 7, 3, 9, 6, 10, 1, 7, 5, 2, 11, 9, 3, 6, 8, 4, 9, 1, 5, 11, 2, 8, 6, 3, 12, 10, 4, 7, 5, 1, 8, 10, 2, 6, 12, 3, 9, 7, 4, 13, 11
Offset: 1

Views

Author

Tanya Khovanova, Nathan Sheffield, and the MIT PRIMES STEP junior group, Mar 22 2025

Keywords

Comments

Under-down-under dealing is a dealing pattern where the top card is placed at the bottom of the deck; then the next card is dealt, then the third card is placed at the bottom of the deck. This pattern repeats until all of the cards have been dealt.
This card dealing is related to a variation on the Josephus problem, where the first person is skipped, the second person is eliminated, and the third person is skipped. Then, the process repeats. The card in row n and column k is x if and only if in the corresponding Josephus problem with n people, the person number x is the k-th person eliminated. Equivalently, each row of Josephus triangle A382358(n) is an inverse permutation of the corresponding row of this triangle.
The total number of moves for row n is 3n-1.
The first column is A382356(n): the order of elimination of the first person in the Josephus problem.
The index of the largest number in row n is A382355(n), corresponding to the index of the freed person in the corresponding Josephus problem.
T(n,3j-1) = j, for 3j <= n.

Examples

			Consider a deck of four cards arranged in the order 2,1,3,4. Card 2 goes under, card 1 is dealt, and card 3 goes under. After the first round, the deck is ordered 4,2,3. Now, card 4 goes under, and card 2 is dealt, and card 3 goes under. After the second round, the deck is ordered 4,3. Now card 4 goes under, and card 3 is dealt. In the last round, card 4 is dealt. The dealt cards are in order. Thus, the fourth row of the triangle is 2,1,3,4.
Table begins:
  1;
  2, 1;
  3, 1, 2;
  2, 1, 3, 4;
  4, 1, 5, 3, 2;
  4, 1, 3, 5, 2, 6;
  3, 1, 7, 5, 2, 4, 6;
  5, 1, 7, 4, 2, 8, 6, 3;
		

Crossrefs

Programs

  • Python
    def T(n, A):
        return invPerm(J(n,A))
    def J(n,A):
        l=[]
        for i in range(n):
            l.append(i+1)
        index = 0
        P=[]
        for i in range(n):
            index+=A[i]
            index=index%len(l)
            P.append(l[index])
            l.pop(index)
        return P
    def invPerm(p):
        inv = []
        for i in range(len(p)):
            inv.append(None)
        for i in range(len(p)):
            inv[p[i]-1]=i+1
        return inv
    def UDU(n):
        return [1] + [2 for i in range(n)]
    seq = []
    for i in range(20):
        seq += T(i,UDU(i))
    print(", ".join([str(v) for v in seq]))
    
  • Python
    def row(n):
        i, J, out = 0, list(range(1, n+1)), []
        while len(J) > 1:
            i = (i + 1)%len(J)
            out.append(J.pop(i))
            i = (i + 1)%len(J)
        out += [J[0]]
        return [out.index(j)+1 for j in list(range(1, n+1))]
    print([e for n in range(1, 14) for e in row(n)]) # Michael S. Branicky, Mar 27 2025

Formula

For any n, we have T(n,2) = 1. T(1,1) = 1; T(2,1) = 2. For n > 2, T(n,1) = T(n-1,n-2) + 1 and T(n,3) = T(n-1,n-1) + 1. For n > 3 and k > 3, T(n,k) = T(n-1,k-3) + 1.

A382355 A version of the Josephus problem: a(n) is the surviving integer under the skip-eliminate-skip version of the elimination process.

Original entry on oeis.org

1, 1, 1, 4, 3, 6, 3, 6, 9, 3, 6, 9, 12, 1, 4, 7, 10, 13, 16, 19, 1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46, 49, 52, 55, 58, 61, 64, 67, 70, 3, 6
Offset: 1

Views

Author

Tanya Khovanova, Nathan Sheffield, and the MIT PRIMES STEP junior group, Mar 22 2025

Keywords

Comments

This variation of the Josephus problem is related to under-down-under card dealing.

Examples

			Consider 4 people in a circle in order 1,2,3,4. In the first round, person 1 is skipped, then person 2 is eliminated, then person 3 is skipped. Now people are in order 4,1,3. In the second round, person 4 is skipped, person 1 is eliminated, and person 3 is skipped. Now people are in order 4,3. In the third round person 3 is eliminated. Person 4 is freed. Thus, a(4) = 4.
		

Crossrefs

Programs

  • Python
    def J(n,A):
        l=[]
        for i in range(n):
            l.append(i+1)
        index = 0
        P=[]
        for i in range(n):
            index+=A[i]
            index=index%len(l)
            P.append(l[index])
            l.pop(index)
        return P
    def invPerm(p):
        inv = []
        for i in range(len(p)):
            inv.append(None)
        for i in range(len(p)):
            inv[p[i]-1]=i+1
        return inv
    def survivor(n, A):
        return J(n, A)[n-1]
    def UDU(n):
        return [1] + [2 for i in range(n)]
    seq = []
    for i in range(1,20):
        seq += [survivor(i, UDU(i))]
    print(", ".join([str(v) for v in seq]))
    
  • Python
    def a(n):
        c, i, J = 1, 0, list(range(1, n+1))
        while len(J) > 1:
            i = (i + 1)%len(J)
            q = J.pop(i)
            i = (i + 1)%len(J) # skip the third
        return J[0]
    print([a(n) for n in range(1, 73)]) # Michael S. Branicky, Mar 24 2025

A382356 Elimination order of the first person in a variation of the Josephus problem, where there are n people total. During each round the first person is skipped, the second is eliminated and the third person is skipped. Then the process repeats.

Original entry on oeis.org

1, 2, 3, 2, 4, 4, 3, 5, 7, 4, 10, 9, 5, 14, 9, 6, 10, 15, 7, 18, 21, 8, 19, 14, 9, 15, 24, 10, 21, 28, 11, 23, 19, 12, 20, 26, 13, 31, 28, 14, 36, 24, 15, 25, 43, 16, 47, 39, 17, 44, 29, 18, 30, 44, 19, 40, 50, 20, 42, 34, 21, 35, 45, 22, 57, 47, 23, 55, 39, 24
Offset: 1

Views

Author

Tanya Khovanova, Nathan Sheffield, and the MIT PRIMES STEP junior group, Mar 22 2025

Keywords

Comments

This elimination process is related to under-down-under card dealing.
a(3k-2) = k.

Examples

			Consider n people. Four people are in order 1,2,3,4. In the first round, the first person is skipped, the second person is eliminated, and the third person is skipped. Now people are ordered 4,1,3. In the second round, person 4 is skipped, and person 1 is eliminated. Thus, person 1 is eliminated in the second round and a(4) = 2.
		

Crossrefs

Programs

  • Python
    def T(n, A):
        return invPerm(J(n,A))
    def J(n,A):
        l=[]
        for i in range(n):
            l.append(i+1)
        index = 0
        P=[]
        for i in range(n):
            index+=A[i]
            index=index%len(l)
            P.append(l[index])
            l.pop(index)
        return P
    def invPerm(p):
        inv = []
        for i in range(len(p)):
            inv.append(None)
        for i in range(len(p)):
            inv[p[i]-1]=i+1
        return inv
    def firstPersonElimOrder(n, A):
        return T(n, A)[0]
    def UDU(n):
        return [1] + [2 for i in range(n)]
    seq = []
    for i in range(1,88):
        seq += [firstPersonElimOrder(i, UDU(i))]
    print(", ".join([str(v) for v in seq]))
    
  • Python
    def a(n):
        c, i, J = 1, 0, list(range(1, n+1))
        while len(J) > 0:
            i = (i + 1)%len(J)
            q = J.pop(i)
            if q == 1: return c
            i = (i + 1)%len(J) # skip the third
            c = c+1
    print([a(n) for n in range(1, 71)]) # Michael S. Branicky, Mar 24 2025
Showing 1-3 of 3 results.