# Perfect riffle shuffles

Take a deck of cards (with indexed position from 1 (top) to 52 (bottom)) and perform a perfect riffle shuffle, such that the top card (1) is still on top and the bottom (52) is still on the bottom.

Amazingly, if you perform 8 such riffle shuffles you will return to where you started.

Obviously, cards 1 and 52 do not change position. Most of the cards will go through some cycle and land back where they started only after 8 riffles.

But two cards will simply swap position back and forth each shuffle.

What are they?

Bonus question:

If you throw in the two jokers, you will have 54 cards. How many riffle shuffles will it take to get this deck back to the starting positions?

Cards in the top half besides 1 always increase from $$k$$ to $$2k-1$$ (because it will be the first card of the $$k$$th pair). Cards in the bottom half besides 52 always decrease from $$m$$ to $$2(m-26)$$ (because it will be the second card of the $$(m-26)$$th pair). Then to return to the original position after two shuffles, the cards must swap between the halves.
If $$k$$ is the position of the card in the top half, then after one shuffle it will move to position $$m=2k-1$$. If it is now in the bottom half ($$m>26$$), it will move to position $$2(m-26)=2(2k-1-26)=4k-54$$ after the second shuffle. To have returned to its initial position, we must have $$4k-54=k\iff3k=54\iff k=18$$, so that $$m=2k-1=35>26$$ holds. The two cards are at positions $$\boxed{18\text{ and }35}$$.
It can be shown using group theory that $$k$$ shuffles will restore a deck of size $$n$$ if $$n-1$$ divides $$2^k-1$$. The sequence of least such $$k$$ for every $$n$$ is in the OEIS, which gives the answer for 54 cards as $$\boxed{52\text{ shuffles}}$$.