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 <-- 5 rounds
6 cards:
order: 123456
1: 462531
2: 516324
3: 341265
4: 254613
5: 635142
6: 123456 <-- 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 <-- 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!