Problem
You have a pile of N cards sorted from 1 to N where card 1 is the one on top and card N is the one at the bottom. We do a shuffle operation on the N cards and the shuffle consists of going through the cards from top to bottom and placing them alternatively one at the bottom and one at the top in order to create a new shuffled pile of cards (i.e: take card 1 place it at the bottom of a new pile, card 2 goes to the top, card 3 goes to the bottom, card 4 goes to the top, etc).
We then take the new pile of cards and shuffle it again using the same procedure.
Example: N = 4
Initial state: 1 - 2 - 3 - 4 (pile of 4 cards from top to bottom)
After 1 shuffle: 4 - 2 - 1 - 3
After 2 shuffles: 3 - 2 - 4 - 1
After 3 shuffles: 1 - 2 - 3 - 4 (Now back to sorted pile of cards, we're done)
So it takes 3 shuffles to get back to initial state.
The question is: given N cards
- How many shuffle operations does it take to get back to sorted cards (1 to N)?
- Is there a mathematical formula to it?
- How to prove mathematically that the cards will always come back in the sorted order?
Let me write out an example to help illustrate what's going on, and that'll help develop an intuition as to how to prove it. Let us take an example of $N=6$. Now, $B$ means a bottom sort, and $T$ a top sort. For this sorting, a card in a particular position will be shuffled to a known new position. Hence, we have a cycle associated with each position
For the 1st number (1), we have the following position shuffle
$$1 - 4 - 2 - 3 - 5 - 6- 1$$
For the 2nd number (2), we have the following
$$2 - 3 - 5- 6- 1 -4 -2$$
Are you noticing something? Let's look at the third number (3)
$$3 - 5 - 6 - 1 - 4 -2 - 3$$
I don't think I have to write any more down. Basically, this shuffle for a given N is a permutation, and if you repeat the same permutation you will always eventually end up with the same sequence as the one you started with.
Rethink is this way for the general $N$ case to see how many moves it should take