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-10 of 37 results. Next

A006694 Number of cyclotomic cosets of 2 mod 2n+1.

Original entry on oeis.org

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

Views

Author

N. J. A. Sloane, Sep 25 2001

Keywords

Comments

a(0) = 0 by convention.
The number of cycles in permutations constructed from siteswap juggling patterns 1, 123, 12345, 1234567, etc., i.e., the number of ball orbits in such patterns minus one.
Also the number of irreducible polynomial factors of the polynomial (x^(2n+1) - 1) / (x - 1) over GF(2). - V. Raman, Oct 04 2012
Also, a(n) is the number of cycles of the Josephus permutation for n elements and a count of 2. For n >= 1, the Josephus permutation is given by the n-th row of A321298. See Knuth 1997 (exercise 1.3.3-29). - Pontus von Brömssen, Sep 18 2022

Examples

			Mod 15 there are 4 cosets: {1, 2, 4, 8}, {3, 6, 12, 9}, {5, 10}, {7, 14, 13, 11}, so a(7) = 4. Mod 13 there is only one coset: {1, 2, 4, 8, 3, 6, 12, 11, 9, 5, 10, 7}, so a(6) = 1.
		

References

  • Donald E. Knuth, The Art of Computer Programming, Vol. 1, 3rd edition, Addison-Wesley, 1997.
  • F. J. MacWilliams and N. J. A. Sloane, The Theory of Error-Correcting Codes, Elsevier/North Holland, 1977, pp. 104-105.
  • N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).

Crossrefs

Cf. A000010, A000374 (number of factors of x^n - 1 over GF(2)), A002326 (order of 2 mod 2n+1), A037226, A064286, A064287, A081844, A139767, A321298.
A001917 gives cycle counts of such permutations constructed only for odd primes.
Second column of A357217.

Programs

  • Maple
    with(group); with(numtheory); gen_rss_perm := proc(n) local a, i; a := []; for i from 1 to n do a := [op(a), ((2*i) mod (n+1))]; od; RETURN(a); end; count_of_disjcyc_seq := [seq(nops(convert(gen_rss_perm(2*j),'disjcyc')),j=0..)];
  • Mathematica
    Needs["Combinatorica`"]; f[n_] := Length[ToCycles[Mod[2Range[2n], 2n + 1]]]; Table[f[n], {n, 0, 100}] (* Ray Chandler, Apr 25 2008 *)
    f[n_] := Length[FactorList[x^(2n + 1) - 1, Modulus -> 2]] - 2; Table[f[n], {n, 0, 100}] (* Ray Chandler, Apr 25 2008 *)
    a[n_] := Sum[ EulerPhi[d] / MultiplicativeOrder[2, d], {d, Divisors[2n + 1]}] - 1; Table[a[n], {n, 0, 99}] (* Jean-François Alcover, Dec 14 2011, after Joerg Arndt *)
  • PARI
    a(n)=sumdiv(2*n+1, d, eulerphi(d)/znorder(Mod(2, d))) - 1; /* cf. A081844 */
    vector(122, n, a(n-1)) \\ Joerg Arndt, Jan 18 2011
    
  • Python
    from sympy import totient, n_order, divisors
    def A006694(n): return sum(totient(d)//n_order(2,d) for d in divisors((n+1<<1)-1,generator=True) if d>1) # Chai Wah Wu, Apr 09 2024

Formula

Conjecture: a((3^n-1)/2) = n. - Vladimir Shevelev, May 26 2008 [This is correct. 2*((3^n-1)/2) + 1 = 3^n and the polynomial (x^(3^n) - 1) / (x - 1) factors over GF(2) into Product_{k=0..n-1} x^(2*3^k) + x^(3^k) + 1. - Joerg Arndt, Apr 01 2019]
a(n) = A081844(n) - 1.
a(n) = A064286(n) + 2*A064287(n).
From Vladimir Shevelev, Jan 19 2011: (Start)
1) a(n)=A037226(n) iff 2n+1 is prime;
2) The only case when a(n) < A037226(n) is n=0;
3) If {C_i}, i=1..a(n), is the set of all cyclotomic cosets of 2 mod (2n+1), then lcm(|C_1|, ..., |C_{a(n)}|) = A002326(n). (End)
a(n) = A000374(2*n + 1) - 1. - Joerg Arndt, Apr 01 2019
a(n) = (Sum_{d|(2n+1)} phi(d)/ord(2,d)) - 1, where phi = A000010 and ord(2,d) is the multiplicative order of 2 modulo d. - Jianing Song, Nov 13 2021

Extensions

Additional comments from Antti Karttunen, Jan 05 2000
Extended by Ray Chandler, Apr 25 2008
Edited by N. J. A. Sloane, Apr 27 2008 at the suggestion of Ray Chandler

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

Original entry on oeis.org

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

Views

Author

Tanya Khovanova and the MIT PRIMES STEP junior group, Dec 02 2024

Keywords

Comments

Under-down dealing is a dealing pattern where the top card is put on the bottom of the deck, and the next card is dealt. Then, this pattern repeats until all cards are dealt.
This card dealing is related to the Josephus problem. The card in row n and column k is x if and only if in the Josephus problem with n people, the person number x is the k-th person eliminated. Equivalently, each row of Josephus triangle A321298 is an inverse permutation of the corresponding row of this triangle.
The total number of moves for row n is 2n.
The first column is A225381, the order of elimination of the first person in the Josephus problem.
The index of the largest number in row n is A006257(n), corresponding to the index of the freed person in the Josephus problem.
T(n,2j) = j, for 2j <= n.

Examples

			Suppose there are four cards arranged in order 4,1,3,2. Card 4 goes under, and card 1 is dealt. Now the deck is ordered 3,2,4. Card 3 goes under, and card 2 is dealt. Now the leftover deck is ordered 4,3. Card 4 goes under, and card 3 is dealt. Then card 4 goes under, and card 4 is dealt. The dealt cards are in order. Thus, the fourth row of the triangle is 4,1,3,2.
Triangle begins:
  1;
  2, 1;
  2, 1, 3;
  4, 1, 3, 2;
  3, 1, 5, 2, 4;
  5, 1, 4, 2, 6, 3;
  4, 1, 6, 2, 5, 3, 7;
  8, 1, 5, 2, 7, 3, 6, 4;
  5, 1, 9, 2, 6, 3, 8, 4, 7;
		

Crossrefs

Formula

T(1,1) = 1, for n > 1, T(n,1) = T(n-1,n-1) + 1 and T(n,2) = 1. For n > 1 and k > 2, T(n,k) = T(n-1,k-2) + 1.

A380201 Triangle T(n,k) read by rows, where row n is a permutation of numbers 1 through n, such that if a deck of n cards is prepared in this order, and SpellUnder-Down dealing is used, then the resulting cards are put down in increasing order.

Original entry on oeis.org

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

Views

Author

Tanya Khovanova and the MIT PRIMES STEP junior group, Jan 16 2025

Keywords

Comments

In Spell Under-Down dealing, we spell the positive integers starting from O-N-E, moving 1 card from the top of the deck underneath the deck for each letter, followed by dealing or "putting down" the top card. So we start by putting 3 cards under for O-N-E, then we deal a card. Then we put 3 cards under for T-W-O, then we deal a card. Then we put 5 cards under for T-H-R-E-E, and subsequently deal a card. This dealing sequence is highly irregular because it depends on English spelling. The dealing pattern starts: UUUDUUUDUUUUUD, 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 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 A380247 is an inverse permutation of the corresponding row of this triangle. The first column is A380246, the order of elimination of the first person in the corresponding Josephus problem. The index of the largest number in row n is A380204(n), corresponding to the index of the freed person in the corresponding Josephus problem. The number of card moves if we start with n cards is A380202 = A067278(n) + n.

Examples

			Triangle begins:
  1;
  2, 1;
  1, 3, 2;
  2, 4, 3, 1;
  5, 3, 2, 1, 4;
  4, 2, 5, 1, 3, 6;
  2, 3, 4, 1, 6, 5, 7;
  5, 6, 8, 1, 7, 4, 3, 2;
  ...
For n = 4 suppose there are four cards arranged in order 2, 4, 3, 1. Three cards go under for each letter in O-N-E, then 1 is dealt. Now the deck is ordered 2,4,3. Three cards go under for each letter in T-W-O, then card 2 is dealt. Now the leftover deck is ordered 4,3. Five cards go under for each letter in T-H-R-E-E, then card 3 is dealt. Finally, card 4 is dealt. The dealt cards are in numerical order. Thus, the fourth row of the triangle is 2, 4, 3, 1.
		

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("-", ""))
    def nthRow(n):
        l = []
        for i in range(0,n):
            l.append(0)
        zp = 0
        for j in range(1,n+1):
            zc = 0
            while zc <= spell(j):
                if l[zp] == 0:
                    zc += 1
                zp += 1
                zp = zp % n
            l[zp-1] = str(j)
        return l
    l = []
    for i in range(1,20):
        l += nthRow(i)
    print(", ".join(l))

A380204 A version of the Josephus problem: a(n) is the surviving integer under the spelling version of the elimination process.

Original entry on oeis.org

1, 1, 2, 2, 1, 6, 7, 3, 5, 3, 5, 6, 10, 9, 2, 13, 3, 16, 10, 2, 15, 6, 15, 6, 21, 1, 7, 23, 26, 6, 20, 12, 27, 29, 7, 2, 36, 11, 6, 7, 32, 6, 32, 43, 10, 31, 7, 5, 42, 1, 17, 48, 7, 31, 53, 25, 42, 43, 29, 39, 51, 25, 43, 7, 26, 59, 15, 10, 60, 69, 13, 57, 54, 66, 57, 30, 9, 35, 64, 9, 65, 1, 15, 3, 79, 47, 86, 7
Offset: 1

Views

Author

Tanya Khovanova and the MIT PRIMES STEP junior group, Jan 16 2025

Keywords

Comments

Arrange n people numbered 1, 2, 3, ..., n in a circle, increasing clockwise. Starting with the person numbered 1, 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 4. This leaves the remaining people in the order 1, 2, 3. The second person eliminated is number 1; the people left are in the order 2, 3. The next person eliminated is numbered 3, leaving only the person numbered 2. Thus a(4) = 2.
		

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:
            i = (i + f(c))%len(J)
            q = J.pop(i)
            c = c+1
        return J[0]
    print([a(n) for n in range(1, 89)]) # Michael S. Branicky, Jan 26 2025

Extensions

Terms a(22) and beyond corrected by Michael S. Branicky, Feb 15 2025

A380246 Elimination order of the first person in a variation of the Josephus problem, where the number of skipped people correspond to the number of letters in consecutive numbers, called SpellUnder-Down.

Original entry on oeis.org

1, 2, 1, 2, 5, 4, 2, 5, 6, 4, 6, 10, 3, 12, 6, 8, 15, 4, 13, 19, 14, 17, 5, 22, 18, 26, 6, 20, 13, 17, 19, 23, 7, 25, 21, 31, 22, 32, 8, 31, 38, 20, 29, 9, 27, 18, 43, 10, 15, 50, 37, 20, 16, 41, 11, 21, 39, 36, 34, 32, 29, 12, 36, 50, 27, 53, 35, 19, 45, 67, 13, 20, 70, 59, 74, 26, 21, 40, 65, 14, 49, 82, 33, 43, 28, 34, 53, 15
Offset: 1

Views

Author

Tanya Khovanova and the MIT PRIMES STEP junior group, Jan 17 2025

Keywords

Comments

Arrange n people numbered 1,2,3,...,n in a circle, increasing clockwise. Starting with the person numbered 1, 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. a(n) is the order of elimination of the first person.

Examples

			Consider n = 4 people. The first person eliminated is number 4. This leaves the remaining people in order 1, 2, 3. The second person eliminated is number 1. Thus, person number 1 is eliminated in the second round, implying that a(4) = 2.
		

Crossrefs

Programs

  • Python
    from num2words import num2words as n2w
    def spell(n):
        return sum(1 for c in n2w(n).replace(" and", "").replace(" ", "").replace(chr(44), "").replace("-", ""))
    def nthRow(n):
        l = []
        for i in range(0,n):
            l.append(0)
        zp = 0
        for j in range(1,n+1):
            zc = 0
            while zc <= spell(j):
                if l[zp] == 0:
                    zc += 1
                zp += 1
                zp = zp % n
            l[zp-1] = str(j)
        return l
    l = []
    for i in range(1,89):
        l += [nthRow(i)[0]]
    print(l)
    
  • 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) > 0:
            i = (i + f(c))%len(J)
            q = J.pop(i)
            if q == 1: return c
            c = c+1
    print([a(n) for n in range(1, 89)]) # Michael S. Branicky, Feb 15 2025

A380202 Number of card moves to deal n cards using the SpellUnder-Down dealing.

Original entry on oeis.org

4, 8, 14, 19, 24, 28, 34, 40, 45, 49, 56, 63, 72, 81, 89, 97, 107, 116, 125, 136, 146, 156, 168, 179, 190, 200, 212, 224, 235, 246, 256, 266, 278, 289, 300, 310, 322, 334, 345, 355, 364, 373, 384, 394, 404, 413, 424, 435, 445, 455, 464, 473, 484, 494, 504, 513, 524, 535, 545, 555, 564, 573, 584, 594, 604, 613, 624, 635, 645
Offset: 1

Views

Author

Tanya Khovanova and the MIT PRIMES STEP junior group, Jan 16 2025

Keywords

Comments

In SpellUnder-Down dealing, we spell the number of the next card, putting a card under for each letter in the number, then we deal the next card. So we start with putting 3 cards under, for O-N-E, then deal, then 3 under for T-W-O, then deal, then 5 under for T-H-R-E-E, then deal. The dealing sequence is highly irregular because it depends on English spelling. The dealing pattern starts: UUUDUUUDUUUUUD.

Examples

			The dealing pattern to deal three cards is UUUDUUUDUUUUUD. It contains 14 letters, thus, a(3) = 14.
		

Crossrefs

Formula

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

A380247 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 the number of people skipped correspond to the number of letters in the next number in English alphabet.

Original entry on oeis.org

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

Views

Author

Tanya Khovanova and the MIT PRIMES STEP junior group, Jan 17 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. Then three people are skipped because number O-N-E has three letters, then the next person is eliminated. Next, three people are skipped because T-W-O has three letters, and the next person is eliminated. Then, five people are skipped because T-H-R-E-E has five letters, and so on. This 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 person in the circle.
In rows 4 and after, the first number is 4. In rows 8 and after, the second number is 8. In rows 14 and after, the third number is 14. In the limit the numbers form sequence A380202.

Examples

			Triangle begins:
  1;
  2, 1;
  1, 3, 2;
  4, 1, 3, 2;
  4, 3, 2, 5, 1;
  4, 2, 5, 1, 3, 6;
  4, 1, 2, 3, 6, 5, 7;
  ...
For n = 4 suppose four people are arranged in a circle corresponding to the fourth row of the triangle. Three people are skipped for each letter in O-N-E; then the 4th person is eliminated. This means the row starts with 4. The next three people are skipped, and the person eliminated is number 1. Thus, the next element in the row is 1. Then, 5 people are skipped, and the next person eliminated is number 3. Similarly, the last person eliminated is number 2. Thus, the fourth row of this triangle is 4, 1, 3, 2.
		

Crossrefs

Programs

  • Python
    from num2words import num2words as n2w
    def spell(n):
        return sum(1 for c in n2w(n).replace(" and", "").replace(" ", "").replace(chr(44), "").replace("-", ""))
    def inverse_permutation(p):
        inv = [0] * len(p)
        for i, x in enumerate(p):
            inv[x-1] = i +1
        return inv
    def nthRow(n):
        l = []
        for i in range(0,n):
            l.append(0)
        zp = 0
        for j in range(1,n+1):
            zc = 0
            while zc <= spell(j):
                if l[zp] == 0:
                    zc += 1
                zp += 1
                zp = zp % n
            l[zp-1] = j
        return l
    l = []
    for i in range(1,15):
        l += inverse_permutation(nthRow(i))
    print(l)
    
  • 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 = 1, 0, list(range(1, n+1))
        out = []
        while len(J) > 1:
            i = (i + f(c))%len(J)
            q = J.pop(i)
            out.append(q)
            c = c+1
        out.append(J[0])
        return out
    print([e for n in range(1, 15) for e in row(n)]) # Michael S. Branicky, Feb 15 2025

A380248 The order of the 13 cards of one suit such that after the SpellUnder-Down deal the cards are in order; a(n) is the n-th card in the deck.

Original entry on oeis.org

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

Views

Author

Tanya Khovanova and the MIT PRIMES STEP junior group, Jan 17 2025

Keywords

Comments

Number 1 corresponds to ace, 11 to jack, 12 to queen, 13 to king.
In the SpellUnder-Down deal, we spell the next card, putting a card under for each letter in the name, then we deal the next card. So we start with putting 3 cards under for A-C-E, then deal, then 3 cards under for T-W-O, then deal, then 5 cards under for T-H-R-E-E, then deal. The dealing sequence is highly irregular because it depends on English spelling. The dealing pattern starts: UUUDUUUDUUUUUD.
The sequence is a permutation of 13 numbers.

Examples

			The first card dealt is the fourth card in the deck, thus, the fourth card must be an ace.
		

Crossrefs

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

Original entry on oeis.org

1, 1, 1, 4, 4, 1, 7, 4, 1, 7, 4, 10, 7, 13, 10, 16, 13, 1, 16, 4, 19, 7, 22, 10, 25, 13, 1, 16, 4, 19, 7, 22, 10, 25, 13, 28, 16, 31, 19, 34, 22, 37, 25, 40, 28, 43, 31, 46, 34, 49, 37, 52, 40, 1, 43, 4, 46, 7, 49, 10, 52, 13, 55, 16, 58, 19, 61, 22, 64, 25, 67
Offset: 1

Views

Author

Robert W. Vallin, Aug 18 2020

Keywords

Comments

This variation of the Josephus problem is related to under-down-down card dealing. - Tanya Khovanova, Apr 14 2025

Examples

			Consider 4 people in a circle in order 1,2,3,4. In the first round, person 1 is skipped and persons 2 and 3 are eliminated. Now people are in order 4,1. In the second round, person 4 is skipped and person 1 is eliminated. Person 4 is freed. Thus, a(4) = 4. - _Tanya Khovanova_, Apr 14 2025
		

Crossrefs

Programs

  • Mathematica
    nxt[{n_,a_,b_}]:={n+1,b,If[Mod[a+3,n+1]!=0,Mod[a+3,n+1],n+1]}; NestList[nxt,{2,1,1},70][[;;,2]] (* Harvey P. Dale, Jul 27 2024 *)
  • PARI
    a(n) = if (n <= 2, 1, my(x = (a(n-2) + 3) % n); if (x, x, n)); \\ Michel Marcus, Aug 20 2020
    
  • PARI
    a(n) = if (n<=1, return(1)); my(v=vector(n, i, i), w); while (#v > 3, if (#v <=3, w = [], w = vector(#v-3, k, v[k+3])); w = concat(w, Vec(v, 1)); v = w;); v[1]; \\ Michel Marcus, Mar 25 2025

Formula

a(1) = 1, a(2) = 1, a(n) = (a(n-2) + 3) (mod n) if (a(n-2) + 3) (mod n) is not 0; a(n) = n if (a(n-2) + 3) (mod n)=0.
Any number n can be written as either 2*(3^k) + 2m (where 0 <= m < 3^k, k = 0,1,2,...) or 3^k + 2m (where 0 <= m < 3^k, k = 0,1,2,...), in either case a(n) = 3m + 1.

Extensions

More terms from Michel Marcus, Aug 20 2020
Title corrected by Tanya Khovanova, Apr 14 2025

A381050 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-under-down 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, 4, 2, 3, 1, 4, 2, 3, 5, 1, 5, 2, 3, 6, 4, 1, 7, 2, 3, 6, 4, 5, 1, 6, 2, 3, 7, 4, 5, 8, 1, 7, 2, 3, 9, 4, 5, 8, 6, 1, 10, 2, 3, 8, 4, 5, 9, 6, 7, 1, 8, 2, 3, 9, 4, 5, 11, 6, 7, 10, 1, 9, 2, 3, 12, 4, 5, 10, 6, 7, 11, 8, 1, 12, 2, 3, 10, 4, 5, 11, 6, 7, 13, 8, 9
Offset: 1

Views

Author

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

Keywords

Comments

Down-under-down dealing is a dealing pattern where the top card is dealt, the second card is placed at the bottom of the deck, then the third card is 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 the first person is eliminated, the second person is skipped, and the third person is 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 A383076 is an inverse permutation of the corresponding row of this triangle.
The total number of moves for row n is A032766(n) = floor(3n/2).
The index of the largest number in row n is A381051(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 1,4,2,3. In round 1, card 1 is dealt, card 4 goes under, card 2 is dealt. Now the deck is ordered 3,4. In round 2, card 3 is dealt, card 4 goes under, then card 4 is dealt. The dealt cards are in order. Thus, the fourth row of the triangle is 1,4,2,3.
Table begins:
  1;
  1, 2;
  1, 3, 2;
  1, 4, 2, 3;
  1, 4, 2, 3, 5;
  1, 5, 2, 3, 6, 4;
  1, 7, 2, 3, 6, 4, 5;
  1, 6, 2, 3, 7, 4, 5, 8;
		

Crossrefs

Programs

  • Mathematica
    row[n_]:=Module[{ds,res,k,i=1,len},ds=CreateDataStructure["Queue",Range[n]];res=CreateDataStructure["FixedArray",n];While[(ds["Length"]>=2),res["SetPart",i++,ds["Pop"]];ds["Push",ds["Pop"]];If[ds["Length"]>1,res["SetPart",i++,ds["Pop"]];]];res["SetPart",n,ds["Pop"]];Flatten[PositionIndex[res["Elements"]]/@Range[n]]];
    Array[row, 13, 1] // Flatten (* Shenghui Yang, May 11 2025 *)
  • Python
    def row(n):
        i, J, out = 0, list(range(1, n+1)), []
        while len(J) > 1:
            i = i%len(J)
            out.append(J.pop(i))
            i = (i + 1)%len(J)
            #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,3j) = 2j, for 3j <= n. T(n,3j+1) = 2j+1, for 3j+1 <= n.
Showing 1-10 of 37 results. Next