login
Number of steps to return a deck of n cards to its original state (original order and all cards face up) under a cyclic signed prefix-reversal shuffle: repeatedly flip the top 1 card, then the top 2, ..., then all n cards, cycling back to 1 until the initial state is restored.
0

%I #21 Apr 20 2026 00:15:41

%S 2,8,9,24,50,72,28,64,162,60,121,240,234,392,75,160,204,648,228,400,

%T 294,264,529,504,200,1352,540,504,1682,1800,186,384,2178,748,1225,324,

%U 740,1140,1521,2160,3362,336,1204,484,540,460,1692,2304,1470,5000,2601,624

%N Number of steps to return a deck of n cards to its original state (original order and all cards face up) under a cyclic signed prefix-reversal shuffle: repeatedly flip the top 1 card, then the top 2, ..., then all n cards, cycling back to 1 until the initial state is restored.

%C Starting with a deck of n cards labeled 1..n, all face up, in their natural order from top to bottom, one full step consists of n sub-steps. In sub-step k (k = 1, 2, ..., n), the top k cards are physically reversed as a block: their order is inverted and each card is flipped (face-up becomes face-down and vice versa). This constitutes one full step. The sequence a(n) counts how many full steps are required for the deck to return exactly to the initial state: same order and all cards face up.

%H Fabio Longo, <a href="https://jeriko001.github.io/Card-permutation/">Card Permutation Simulator</a>

%F a(n) = n * A002326(n). - _Sean A. Irvine_, Apr 20 2026

%e Example for n=3, starting with deck [1u, 2u, 3u]

%e (u=face up, d=face down, top of deck is leftmost):

%e Step 1:

%e k=1: flip top 1 -> [1d, 2u, 3u]

%e k=2: flip top 2 -> [2d, 1u, 3u]

%e k=3: flip top 3 -> [3d, 1d, 2u]

%e Step 2:

%e k=1: flip top 1 -> [3u, 1d, 2u]

%e k=2: flip top 2 -> [1u, 3d, 2u]

%e k=3: flip top 3 -> [2d, 3u, 1d]

%e Step 3:

%e k=1: flip top 1 -> [2u, 3u, 1d]

%e k=2: flip top 2 -> [3d, 2d, 1d]

%e k=3: flip top 3 -> [1u, 2u, 3u] = initial state

%e Thus a(3) = 3 full steps = 9 sub-steps.

%o (Python)

%o def a(n):

%o # Each card: [id, face] where face 1=up, 0=down

%o deck = [[i, 1] for i in range(n)]

%o steps = 0

%o while True:

%o for k in range(1, n + 1):

%o packet = deck[:k]

%o packet.reverse()

%o for card in packet:

%o card[1] = 1 - card[1]

%o deck = packet + deck[k:]

%o steps += 1

%o if all(deck[i][0] == i and deck[i][1] == 1 for i in range(n)):

%o return steps

%o print([a(n) for n in range(1, 21)])

%Y Cf. A002326, A289386, A323712.

%K nonn

%O 1,1

%A _Fabio Longo_, Apr 10 2026

%E More terms from _Sean A. Irvine_, Apr 20 2026