login
a(n) is the number of permutations of 1..n that win this game. Take a shuffled pack of cards labeled 1..n, repeat this: look at the top card's value, X. Move X cards from the top of the deck to the back, one at a time. If you ever end up with the first card back at the top, you win.
0

%I #31 Oct 17 2025 00:01:46

%S 1,1,4,10,56,304,1956,14856,130008,1237440,13084540,151656128,

%T 1907139360,25850635872,377651957184,5861540577920,97217787650368,

%U 1706293248844992,31680915068666736,618994402356397440

%N a(n) is the number of permutations of 1..n that win this game. Take a shuffled pack of cards labeled 1..n, repeat this: look at the top card's value, X. Move X cards from the top of the deck to the back, one at a time. If you ever end up with the first card back at the top, you win.

%e For a(3), the permutation 1 2 3 counts as a win. This is what happens:

%e 1 2 3

%e 2 3 1 (1 card to the back)

%e 1 2 3 (2 cards to the back)

%e Win!

%e For a(3), the permutation 1 3 2 is not counted:

%e 1 3 2

%e 3 2 1 (1 card to the back)

%e 3 2 1 (3 cards to the back)

%e Infinite loop: lose!

%e For a(4), the permutation 2 1 3 4 is not counted:

%e 2 1 3 4

%e 3 4 2 1

%e 1 3 4 2

%e 3 4 2 1

%e Infinite loop: lose!

%o (Python)

%o from itertools import permutations

%o def a(n):

%o seq = list(range(1,n+1))

%o t = 0

%o for p in permutations(seq):

%o i = 0

%o for step in range(n):

%o i += p[i]

%o if i == n:

%o t += 1

%o break

%o i = i % n

%o return t

%K nonn,more

%O 1,3

%A _Christian Perfect_, Oct 03 2025

%E a(12)-a(14) from _Michael S. Branicky_, Oct 07 2025

%E a(15)-a(18) from _Jason Yuen_, Oct 07 2025

%E a(19)-a(20) from _Jason Yuen_, Oct 16 2025