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.

A321580 Numbers k such that it is possible to reverse a deck of k cards by a sequence of perfect Faro shuffles with cut.

This page as a plain text file.
%I A321580 #26 Mar 21 2023 18:09:02
%S A321580 1,2,4,8,10,12,16,18,24,26,28,32,36,40,42,52,56,58,60,64,66,80,82,96,
%T A321580 98,100,106,108,112,120,124,128,130,136,138,144,148,156,162,168,170,
%U A321580 172,176,178,180,184,192,196,200,204,208,210,226,228,240,242,248,250
%N A321580 Numbers k such that it is possible to reverse a deck of k cards by a sequence of perfect Faro shuffles with cut.
%C A321580 Except for 1, it isn't possible to shuffle backwards an odd number of cards.
%H A321580 Andrew Howroyd, <a href="/A321580/b321580.txt">Table of n, a(n) for n = 1..2000</a>
%H A321580 Wikipedia, <a href="https://en.wikipedia.org/wiki/Faro_shuffle">Faro shuffle</a>
%e A321580 For a deck of 4 cards we'll have the following sequence of shuffles: 1234, 2413, 4321, 3142, 1234. Observe that the reverse order (4321) of 1234 appears in the sequence of shuffles.
%e A321580 For a deck of 5 cards: 12345, 24135, 43215, 31425, 12345. Observe that the reverse order (54321) of 12345 does not appear in the sequence of shuffles.
%o A321580 (Python)
%o A321580 for n in range(1, 501):
%o A321580     cards = [i for i in range(1, n + 1)]
%o A321580     reverse = cards[::-1]
%o A321580     shuffled = cards.copy()
%o A321580     reversein = False
%o A321580     for i in range(n):
%o A321580         evens = shuffled[1::2]
%o A321580         odds = shuffled[0::2]
%o A321580         shuffled = evens + odds
%o A321580         if shuffled == reverse:
%o A321580             reversein = True
%o A321580             print(n, end=", ")
%o A321580             break
%o A321580 (PARI)
%o A321580 shuffle(v)={my(h=#v\2); vector(#v, i, if(i<=h, 2*i, 2*(i-h)-1))}
%o A321580 permcycs(v)={my(f=vector(#v), L=List()); for(i=1, #v, if(!f[i], my(T=List(), j=i); while(!f[j], f[j]=1; listput(T,j); j=v[j]); listput(L, Vec(T)))); Vec(L)}
%o A321580 ok(n)={my(v=permcycs(shuffle([1..n])), e=-1); for(k=1, #v, my(p=v[k]); if(#p>1||n%2==0||2*p[1]<>n+1, my(h=#p\2); if(e<0, e=valuation(#p,2)); if(valuation(#p,2)<>e || e==0 || p[1..h]+p[h+1..2*h]<>vector(h,i,n+1), return(0)))); 1} \\ _Andrew Howroyd_, Nov 13 2018
%Y A321580 Cf. A024222, A071642, A321512.
%K A321580 nonn
%O A321580 1,2
%A A321580 _Pedro Menezes_, Nov 13 2018