OFFSET
1,1
COMMENTS
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.
LINKS
Fabio Longo, Card Permutation Simulator
FORMULA
a(n) = n * A002326(n). - Sean A. Irvine, Apr 20 2026
EXAMPLE
Example for n=3, starting with deck [1u, 2u, 3u]
(u=face up, d=face down, top of deck is leftmost):
Step 1:
k=1: flip top 1 -> [1d, 2u, 3u]
k=2: flip top 2 -> [2d, 1u, 3u]
k=3: flip top 3 -> [3d, 1d, 2u]
Step 2:
k=1: flip top 1 -> [3u, 1d, 2u]
k=2: flip top 2 -> [1u, 3d, 2u]
k=3: flip top 3 -> [2d, 3u, 1d]
Step 3:
k=1: flip top 1 -> [2u, 3u, 1d]
k=2: flip top 2 -> [3d, 2d, 1d]
k=3: flip top 3 -> [1u, 2u, 3u] = initial state
Thus a(3) = 3 full steps = 9 sub-steps.
PROG
(Python)
def a(n):
# Each card: [id, face] where face 1=up, 0=down
deck = [[i, 1] for i in range(n)]
steps = 0
while True:
for k in range(1, n + 1):
packet = deck[:k]
packet.reverse()
for card in packet:
card[1] = 1 - card[1]
deck = packet + deck[k:]
steps += 1
if all(deck[i][0] == i and deck[i][1] == 1 for i in range(n)):
return steps
print([a(n) for n in range(1, 21)])
CROSSREFS
KEYWORD
nonn
AUTHOR
Fabio Longo, Apr 10 2026
EXTENSIONS
More terms from Sean A. Irvine, Apr 20 2026
STATUS
approved
