Obtaining ordering of cards You are given a deck containing n cards.  While holding the deck:


Take the top card off the deck and set it on the table
Take the next card off the top and put it on the bottom of the deck in your hand.
Continue steps 1 and 2 until all cards are on the table.  This is a round.
Pick up the deck from the table and repeat steps 1-3 until the deck is in the original order.


Write a program to determine how many rounds it will take to put a deck back into the original order.

I found some answers online that had answers online for comparing and I cannot get the same answers. Either they are wrong or I am completely wrong. I went through a few examples of my own got these answers:

5 cards:
    order: 12345

1: 24531
2: 43152
3: 35214
4: 51423
5: 12345   &lt;-- 5 rounds


6 cards:

order: 123456

1: 462531
2: 516324
3: 341265
4: 254613
5: 635142
6: 123456   &lt;-- 6 rounds


Answers I found online were:

Problem: http://www.velocityreviews.com/forums/t641157-solution-needed-urgent.html

Answer: http://www.velocityreviews.com/forums/t641157-p2-solution-needed-urgent.html   &lt;-- last post


I found another solution that has the same solution as mine but not sure on any solutions credibility:

http://entrepidea.com/algorithm/algo/shuffleCards.pdf


I was wondering if anyone has done this problem before and would be able to confirm which answers are correct. I need something to test against to see if my program is giving the correct output. THANKS!
Python
def game(a):
    deck = range(1,a+1)
    #store the deck
    origDeck = []
    #copy the deck
    origDeck.extend(deck)
    table =[]
    ans = 0
    while 1:
        while len(deck) &gt; 0:
            table.append(deck.pop(0))
            if len(deck) == 0:
                break
            deck.append(deck.pop(0))
        table.reverse()
        deck,table=table,deck
        ans+=1
        #this is the condition that exits the infinite loop
        if deck==origDeck:
            break
    print ans

Calling game(n) prints the number of rounds for n cards. The code can be easily changed to allow for printing the deck between rounds (add print deck before if deck==origDeck).

Tests (1 through 50):
1: 1
2: 2
3: 3
4: 2
5: 5
6: 6
7: 5
8: 4
9: 6
10: 6
11: 15
12: 12
13: 12
14: 30
15: 15
16: 4
17: 17
18: 18
19: 10
20: 20
21: 21
22: 14
23: 24
24: 90
25: 63
26: 26
27: 27
28: 18
29: 66
30: 12
31: 210
32: 12
33: 33
34: 90
35: 35
36: 30
37: 110
38: 120
39: 120
40: 26
41: 41
42: 42
43: 105
44: 30
45: 45
46: 30
47: 60
48: 48
49: 120
50: 50

31 produces a peculiar output; it goes through 210 rounds.
It appears that primes have large cycles. For example, 97 has the largest cycle under 100: 6435.