The Shuffle
Start with n cards labeled 1 to n, all face up, in natural order. 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). a(n) counts how many full steps are required to return to the original state.
Closed Form
Where A002326(n) is the multiplicative order of 2 modulo (2n+1) — the smallest k such that 2k ≡ 1 (mod 2n+1).
Formula contributed by Sean A. Irvine · Apr 20 2026
The deep reason: each full step acts as multiplication by 2 modulo (2n+1) on a cyclic encoding of the deck state. The deck returns to its initial configuration after exactly A002326(n) full cycles — each consisting of n sub-steps.
First 20 Terms
| n | A002326(n) | a(n) = n × A002326(n) |
|---|
Walkthrough: n = 3
Starting deck: [1↑, 2↑, 3↑]. Each card chip shows its label; rotated = face down. After 3 full steps (9 sub-steps total), the deck returns to its initial state.
Python Implementation
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)]) # Verified manually and computationally up to n=20