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.

Previous Showing 21-30 of 39 results. Next

A381127 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 Down-SpellUnder dealing is used, then the resulting cards will be dealt in increasing order.

Original entry on oeis.org

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

Views

Author

Tanya Khovanova, Nathan Sheffield, and the MIT PRIMES STEP junior group, Feb 14 2025

Keywords

Comments

In Down-SpellUnder dealing, we deal the first card, then spell the positive integers starting from O-N-E, moving a card from the top of the deck underneath the deck for each letter in the English spelling of the number, followed by dealing or "putting down" the top card. So we start by dealing the first card, then putting 3 cards under because O-N-E has three letters, then we deal the next card. Then we put 3 cards under because T-W-O has three letters, then we deal a card. Then we put 5 cards under for T-H-R-E-E, and so on. This dealing sequence is highly irregular because it depends on English spelling. The dealing pattern starts: DUUUDUUUDUUUUUD, where each "U" corresponds to putting a card “under” and each "D" corresponds to dealing a card “down”.
This card dealing can be thought of as a generalized version of the Josephus problem. In this version of the Josephus problem, we start by executing the first person, then spell the positive integers in increasing order, each time skipping past 1 person for each letter and executing the next person. The card in row n and column k is x if and only if in the corresponding Josephus problem with n people, the person numbered x is the k-th person eliminated.
Equivalently, each row of the corresponding Josephus triangle A381114 is an inverse permutation of the corresponding row of this triangle. The first column contains only ones, since person number 1 always dies first in the corresponding Josephus problem. The index of the largest number in row n is A381129(n), corresponding to the index of the freed person in the corresponding Josephus problem. The number of card moves that we need to take if we start with n cards is A381128(n).

Examples

			Triangle begins:
 1;
 1, 2;
 1, 3, 2;
 1, 2, 4, 3;
 1, 3, 5, 4, 2;
 1, 6, 4, 3, 2, 5;
 1, 5, 3, 6, 2, 4, 7;
 1, 3, 4, 5, 2, 7, 6, 8;
  ...
For n = 4, suppose there are four cards arranged in the order 1,2,4,3. Card 1 is dealt, and then three cards go under the deck because O-N-E has three letters. Now, the deck is ordered 2,4,3. Card 2 is dealt, and three cards go under because T-W-O has three letters. Now, the leftover deck is ordered 3,4. Card 3 is dealt, and five cards go under because T-H-R-E-E has five letters. Then card 4 is dealt. The dealt cards are in numerical order. Thus, the fourth row of the triangle is 1, 2, 4, 3.
		

Crossrefs

Programs

  • Python
    from num2words import num2words as n2w
    def f(n): return sum(1 for c in n2w(n).replace(" and", "") if c.isalpha())
    def row(n):
        c, i, J, out = 1, 0, list(range(1, n+1)), []
        while len(J) > 1:
            q = J.pop(i)
            out.append(q)
            i = (i + f(c))%len(J)
            c = c+1
        out.append(J[0])
        return [out.index(j)+1 for j in list(range(1, n+1))]
    print([e for n in range(1, 15) for e in row(n)]) # Michael S. Branicky, Feb 16 2025

A381128 The number of card moves required to deal n cards using Down-SpellUnder dealing.

Original entry on oeis.org

1, 5, 9, 15, 20, 25, 29, 35, 41, 46, 50, 57, 64, 73, 82, 90, 98, 108, 117, 126, 133, 143, 153, 165, 176, 187, 197, 209, 221, 232, 239, 249, 259, 271, 282, 293, 303, 315, 327, 338, 344, 353, 362, 373, 383, 393, 402, 413, 424, 434, 440, 449, 458, 469, 479, 489, 498, 509, 520, 530, 536, 545, 554, 565, 575, 585, 594, 605
Offset: 1

Views

Author

Tanya Khovanova, Nathan Sheffield, and the MIT PRIMES STEP junior group, Feb 14 2025

Keywords

Comments

In Down-SpellUnder dealing, after dealing the i-th card we move a card from the top of the deck to the bottom for each letter in the English spelling of i. Then we deal the next card and proceed likewise. So we start by dealing card 1, then putting 3 cards under because O-N-E has three letters. Then, we deal the next card, and put three cards under 3 because T-W-O has three letters. We then deal again, put 5 under for T-H-R-E-E, and so on. This dealing sequence is highly irregular because it depends on English spelling. The dealing pattern starts: DUUUDUUUDUUUUUD, where D means 'deal', and U means 'under'.

Examples

			The dealing pattern to deal four cards is DUUUDUUUDUUUUUD. It contains 15 letters, so a(4) = 15.
		

Crossrefs

Programs

  • Python
    from num2words import num2words as n2w
    def spell(n):
        return sum(1 for c in n2w(n).replace(" and", "").replace(" ", "").replace(",", "").replace("-", ""))
    moves_so_far = 0
    l = []
    for i in range(1, 41):
        moves_so_far += 1
        l += [str(moves_so_far)]
        moves_so_far += spell(i)
    print(", ".join(l))

Formula

a(n) = A067278(n-1) + n.

A381129 A version of the Josephus problem: a(n) is the surviving integer under the spelling version of the elimination process, called Down-SpellUnder.

Original entry on oeis.org

1, 2, 2, 3, 3, 2, 7, 8, 4, 6, 4, 6, 7, 11, 10, 3, 14, 4, 17, 11, 3, 16, 7, 16, 7, 22, 2, 8, 24, 27, 7, 21, 13, 28, 30, 8, 3, 37, 12, 7, 8, 33, 7, 33, 44, 11, 32, 8, 6, 43, 2, 18, 49, 8, 32, 54, 26, 43, 44, 30, 40, 52, 26, 44, 8, 27, 60, 16, 11, 61, 70, 14, 58, 55
Offset: 1

Views

Author

Tanya Khovanova, Nathan Sheffield, and the MIT PRIMES STEP junior group, Feb 14 2025

Keywords

Comments

Arrange n people numbered 1, 2, 3, ..., n in a circle, increasing clockwise. Execute the person numbered 1, then spell the letters of O-N-E, moving one person clockwise for each letter. Once you are done, eliminate the next person. Then, spell the letters of T-W-O; in other words, skip three people and eliminate the next person. Following this, spell the letters of T-H-R-E-E; in other words, skip five people and eliminate the next person. Continue until one person remains. The number of this person is a(n).

Examples

			Consider n = 4 people. The first person eliminated is number 1. This leaves the remaining people in the order 2, 3, 4. The second person eliminated is number 2; the people left are in the order 3, 4. The next person eliminated is numbered 4, leaving only the person numbered 3. Thus, a(4) = 3.
		

Crossrefs

Programs

  • Python
    from num2words import num2words as n2w
    def f(n): return sum(1 for c in n2w(n).replace(" and", "") if c.isalpha())
    def a(n):
        c, i, J = 1, 0, list(range(1, n+1))
        while len(J) > 1:
            q = J.pop(i)
            i = (i + f(c))%len(J)
            c = c+1
        return J[0]
    print([a(n) for n in range(1, 75)]) # Michael S. Branicky, Feb 16 2025

Extensions

a(22) and beyond from Michael S. Branicky, Feb 16 2025

A381591 Elimination order of the first person in a variation of the Josephus problem, where there are n people total and two people are skipped each time.

Original entry on oeis.org

1, 1, 2, 4, 2, 6, 6, 3, 9, 6, 4, 7, 11, 5, 11, 15, 6, 13, 11, 7, 12, 16, 8, 23, 18, 9, 22, 16, 10, 17, 31, 11, 27, 30, 12, 35, 21, 13, 22, 37, 14, 30, 35, 15, 32, 26, 16, 27, 35, 17, 47, 37, 18, 53, 31, 19, 32, 47, 20, 57, 56, 21, 51, 36, 22, 37, 65, 23, 49, 70
Offset: 1

Views

Author

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

Keywords

Comments

a(3k-1) = k.

Examples

			Consider n = 4 people. The first person eliminated is number 3. This leaves the remaining people in order 4, 1, 2. The second person eliminated is number 2. Thus, the remaining people in order 4, 1. The next person eliminated is number 4. On the fourth step, person number 1 is eliminated, implying that the order of elimination of the first person is 4: a(4) = 4.
		

Crossrefs

Programs

  • Python
    def UUD(n):
        return invPerm(UUDES(n))
    def UUDES(n):
        l=[]
        for i in range(n):
            l.append(i+1)
        index = 0
        P=[]
        for i in range(n):
            index+=2
            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
    sequence = []
    for i in range(1, 71):
        sequence += [str(UUD(i)[0])]
    print(", ".join(sequence))
    
  • Python
    def a(n):
        c, i, J = 1, 0, list(range(1, n+1))
        while len(J) > 0:
            i = (i + 2)%len(J)
            q = J.pop(i)
            if q == 1: return c
            c = c+1
    print([a(n) for n in range(1, 71)]) # Michael S. Branicky, Mar 24 2025

A381667 Triangle read by row: T(n,k) is the number of the k-th eliminated person in the variation of the Josephus elimination process for n people where two people are skipped each step.

Original entry on oeis.org

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

Views

Author

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

Keywords

Comments

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 skips two numbers and the next number is eliminated. 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.
This variation of the Josephus problem is related to under-under-down card dealing, where the cards of a deck are dealt by alternately cycling two cards from the top "under", and then dealing the next card "down". In particular, T(n,k) is the k-th card dealt in under-under-down dealing if the deck begins in order 1,2,3,...,n.

Examples

			Consider 4 people in a circle. Initially, people numbered 1 and 2 are skipped, and person 3 is eliminated. The remaining people are now in order 4, 1, 2. Then 4 and 1 are skipped, and person 2 is eliminated. The remaining people are in order 4, 1. Now, 4 and 1 are skipped, and 4 is eliminated. Person 1 is eliminated last. Thus, the fourth row of the triangle is 3, 2, 4, 1.
Triangle begins;
  1;
  1, 2;
  3, 1, 2;
  3, 2, 4, 1;
  3, 1, 5, 2, 4;
  3, 6, 4, 2, 5, 1;
  3, 6, 2, 7, 5, 1, 4;
  3, 6, 1, 5, 2, 8, 4, 7;
		

Crossrefs

Programs

  • Python
    def UUDES(n):
        l=[]
        for i in range(n):
            l.append(i+1)
        index = 0
        P=[]
        for i in range(n):
            index+=2
            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
    sequence = []
    for i in range(1,20):
        sequence += [str(v) for v in UUDES(i)]
    print(", ".join(sequence))
    
  • Python
    def row(n):
        i, J, out = 0, list(range(1, n+1)), []
        while len(J) > 0:
            i = (i + 2)%len(J)
            out.append(J.pop(i))
        return out
    print([e for n in range(1, 14) for e in row(n)]) # Michael S. Branicky, Mar 24 2025

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

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.

Original entry on oeis.org

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, 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, 5, 8, 11, 3, 7, 12, 6, 1, 10, 4, 9, 2, 5, 8, 11, 1, 6, 10, 3, 9, 4, 13, 7, 12
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.
The n-th row has n elements.
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.

Examples

			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.
Triangle begins;
  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, 3, 6;
  ...
		

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 UDU(n):
        return [1] + [2 for i in range(n)]
    seq = []
    for i in range(1,20):
        seq += J(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)
        return out + [J[0]]
    print([e for n in range(1, 14) for e in row(n)]) # Michael S. Branicky, Mar 24 2025

A382528 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-down dealing is used, then the resulting cards will be dealt in increasing order.

Original entry on oeis.org

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

Views

Author

Tanya Khovanova, Nathan Sheffield, and the MIT PRIMES STEP junior group, Apr 12 2025

Keywords

Comments

Under-down-down dealing is a dealing pattern where the top card is placed at the bottom of the deck, then the next two cards are dealt. This pattern repeats until all of the cards have been dealt.
This card dealing is related to a variation on the Josephus problem, where one person is skipped, and the next two are eliminated. 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 ??? is an inverse permutation of the corresponding row of this triangle.
The total number of moves for row n is A007494(n) = ceiling(3n/2).
The first column is A381048, the order of elimination of the first person in the Josephus problem.
The index of the largest number in row n is A337191(n), corresponding to the index of the freed person in the corresponding Josephus problem.

Examples

			Consider a deck of four cards arranged in the order 3,1,2,4. Card 3 goes under, then card 1 is dealt, then card 2 is dealt, then card 4 goes under, then cards 3 and 4 are dealt. Thus, the fourth row of the triangle is 3,1,2,4.
Table begins:
1;
2, 1;
3, 1, 2;
3, 1, 2, 4;
4, 1, 2, 5, 3;
6, 1, 2, 5, 3, 4;
5, 1, 2, 6, 3, 4, 7;
6, 1, 2, 8, 3, 4, 7, 5;
		

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 DDU(n):
        return [0] + [(i)%2 for i in range(n)]
    def DUD(n):
        return DDU(n+1)[1:]
    def UDD(n):
        return DUD(n+1)[1:]
    seq = []
    for i in range(1,10):
        seq += T(i, UDD(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%len(J)
            if len(J) > 1:
                out.append(J.pop(i))
        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, Apr 28 2025

Formula

T(n,k) = T(n-2,k-3) + 2. T(1,1) = 1. For the first 3 columns, we have T(n,1) = T(n-2,n-2) + 2, T(n,2) = 1, and T(n,3) = 2.
It follows that T(n,3k+2) = 2k+1, T(n,3k) = 2k.
Previous Showing 21-30 of 39 results. Next