OFFSET
1,2
COMMENTS
Except for 1, it isn't possible to shuffle backwards an odd number of cards.
LINKS
Andrew Howroyd, Table of n, a(n) for n = 1..2000
Wikipedia, Faro shuffle
EXAMPLE
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.
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.
PROG
(Python)
for n in range(1, 501):
cards = [i for i in range(1, n + 1)]
reverse = cards[::-1]
shuffled = cards.copy()
reversein = False
for i in range(n):
evens = shuffled[1::2]
odds = shuffled[0::2]
shuffled = evens + odds
if shuffled == reverse:
reversein = True
print(n, end=", ")
break
(PARI)
shuffle(v)={my(h=#v\2); vector(#v, i, if(i<=h, 2*i, 2*(i-h)-1))}
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)}
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
CROSSREFS
KEYWORD
nonn
AUTHOR
Pedro Menezes, Nov 13 2018
STATUS
approved