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-2 of 2 results.

A323712 Number of the following described shuffles required to return a deck of n cards to its original state. Create two piles by alternating a card from the top of the deck left-right-left-right until the deck is exhausted. Then, placing the left pile on top of the right pile constitutes one shuffle.

Original entry on oeis.org

1, 1, 3, 4, 4, 6, 6, 3, 9, 5, 5, 12, 12, 4, 12, 8, 8, 9, 9, 6, 6, 22, 22, 20, 20, 9, 27, 28, 28, 10, 10, 5, 15, 12, 12, 36, 36, 12, 12, 20, 20, 7, 7, 12, 36, 46, 46, 42, 42, 8, 24, 52, 52, 20, 20, 9, 9, 29, 29, 60, 60, 6, 18, 12, 12, 33, 33, 22, 66, 70, 70, 18
Offset: 1

Views

Author

David Lovler, Jan 24 2019

Keywords

Comments

The card shuffling procedure is the same for even n and odd n.
Here are a few conjectures.
a(n) <= n for all n.
a(p)=a(p-1) and a(p)|p-1 when p is a prime >= 5.
a(n)=a(n-1) and a(n)|n-1 for nonprimes 341=31*11 and 22369621=8191*2731 and probably other pseudoprimes of the form p*((p+2)/3) where p is a Mersenne prime and (p+2)/3 is prime.
n cards are returned to their original state after n shuffles when n=1, 3, 4, 6, 9, 12, 22, 27, 28, 36, 46, 52, 60, 70, 78, 81, ... (A373461) . These values of n are either of the form p-1 where p is an odd prime number or 3^i, i >= 0.
a(c) is relatively small (compared with nearby values) when c is a Catalan number.
a(2n+1)=3*a(2n) or a(2n+1)=a(2n) for all n.

Examples

			For n=4, {a1,a2,a3,a4}-->{a3,a1,a4,a2}-->{a4,a3,a2,a1}-->{a2,a4,a1,a3}-->{a1,a2,a3,a4}, so a(4)=4.
For n=5, {a1,a2,a3,a4,a5}-->{a5,a3,a1,a4,a2}-->{a2,a1,a5,a4,a3}-->{a3,a5,a2,a4,a1}-->{a1,a2,a3,a4,a5}, so a(5)=4.
		

Crossrefs

Cf. A024222, A022998, A163776, A373416 (fixed points).

Programs

  • Maple
    pileShuf := proc(L::list)
        local i,n,shf ;
        shf := [] ;
        n := nops(L) ;
        if type(n,'odd') then
            for i from n to 1 by -2 do
                shf := [op(shf),op(i,L)] ;
            end do:
            for i from n-1 to 2 by -2 do
                shf := [op(shf),op(i,L)] ;
            end do:
        else
            for i from n-1 to 1 by -2 do
                shf := [op(shf),op(i,L)] ;
            end do:
            for i from n to 2 by -2 do
                shf := [op(shf),op(i,L)] ;
            end do:
        end if;
        shf ;
    end proc:
    A323712 := proc(n)
        local L,itr,isord,i;
        L := [seq(i,i=1..n)] ;
        for itr from 1 to n! do
            L := pileShuf(L) ;
            isord := true ;
            for i from 1 to nops(L) do
                if op(i,L) <> i then
                    isord := false ;
                    break ;
                end if;
            end do:
            if isord then
                return itr ;
            end if;
        end do:
        -1 ;
    end proc:
    seq(A323712(n),n=1..50) ; # R. J. Mathar, Aug 02 2024
  • PARI
    perm(n, vn) = {my(va = List(), vb = List()); for (k=1, n, if (k % 2, listput(va, vn[k]), listput(vb, vn[k]));); Vec(concat(Vecrev(va), Vecrev(vb)));}
    a(n) = {my(vn = vector(n,k,k), vs = perm(n, vn), nb = 1); while (vs != vn, vs = perm(n, vs); nb++); nb;} \\ Michel Marcus, Feb 06 2019

Formula

a(2^m) = m if m is odd, a(2^m) = 2m if m is even. - Alois P. Heinz, Feb 15 2019

A263458 Deal a pack of n cards into two piles and gather them up, n/2 times. All n such that this reverses the order of the deck.

Original entry on oeis.org

4, 6, 12, 22, 28, 30, 36, 46, 52, 60, 70, 78, 100, 102, 108, 126, 148, 150, 156, 166, 172, 180, 190, 196, 198, 222, 228, 238, 262, 268, 270, 276, 292, 310, 316, 348, 358, 366, 372, 382, 388, 396, 420, 430, 438, 460, 462, 478, 486, 502, 508, 540, 556, 598
Offset: 1

Views

Author

Christian Perfect, Oct 19 2015

Keywords

Comments

This seems to be A003628(n)-1; that is, each element of this sequence is one less than a prime congruent to 5 or 7 modulo 8.

Examples

			Take a deck of 52 playing cards. Deal it into two piles, then pick up the first pile and put it on top of the other. Do this 26 times. The order of the deck is reversed, so 52 belongs to this sequence.
6 is in the sequence because the 3 shuffles are [1, 2, 3, 4, 5, 6] -> [5, 3, 1, 6, 4, 2] -> [4, 1, 5, 2, 6, 3] -> [6, 5, 4, 3, 2, 1], original reversed. 8 is not in the sequence because the 4 shuffles are [1, 2, 3, 4, 5, 6, 7, 8] -> [7, 5, 3, 1, 8, 6, 4, 2] -> [4, 8, 3, 7, 2, 6, 1, 5] -> [1, 2, 3, 4, 5, 6, 7, 8] -> [7, 5, 3, 1, 8, 6, 4, 2], not the original reversed. - _R. J. Mathar_, Aug 02 2024
		

Crossrefs

Programs

  • Maple
    isA263458 := proc(n)
        local L,itr ;
        L := [seq(i,i=1..n)] ;
        for itr from 1 to n/2 do
            L := pileShuf(L) ; # function code in A323712
        end do:
        for i from 1 to nops(L) do
            if op(-i,L) <> i then
                return false ;
            end if;
        end do:
        true ;
    end proc:
    n := 1;
    for k from 2 do
        if isA263458(k) then
            printf("%d %d\n",n,k) ;
            n := n+1 ;
        end if;
    end do: # R. J. Mathar, Aug 02 2024
  • Sage
    from itertools import cycle
    def into_piles(r,deck):
        packs = [[] for i in range(r)]
        for card, pack in zip(range(1,deck+1),cycle(range(r))):
            packs[pack].insert(0,card)
        out = sum(packs,[])
        return Permutation(out)
    def has_reversing_property(deck):
        p = power(into_piles(2,deck), deck/2)
        return p==into_piles(1,deck)
    [i for i in range(2,400,2) if has_reversing_property(i)]
Showing 1-2 of 2 results.