OK I already posted this in 2 other forums (OT and software), but still I havent find the right answer
So Ill try my luck here
Given a deck of nCards unique cards, cut the deck iCut cards from top and perform a perfect shuffle. A perfect shuffle begins by putting down the bottom card from the top portion of the deck followed by the bottom card from the bottom portion of the deck followed by the next card from the top portion, etc., alternating cards until one portion is used up. The remaining cards go on top. The problem is to find the number of perfect shuffles required to return the deck to its original order. Your function should be declared as:
static long shuffles(int nCards,int iCut);
Find the result of shuffles(1002,101)
any hints of the algorithm???
I know I can just do the algorithm over and over again until it becomes the original deck, however, there MUST be a much more elegant solution
any help?
TIA
EDIT: no this is NOT a HW problem
So Ill try my luck here
Given a deck of nCards unique cards, cut the deck iCut cards from top and perform a perfect shuffle. A perfect shuffle begins by putting down the bottom card from the top portion of the deck followed by the bottom card from the bottom portion of the deck followed by the next card from the top portion, etc., alternating cards until one portion is used up. The remaining cards go on top. The problem is to find the number of perfect shuffles required to return the deck to its original order. Your function should be declared as:
static long shuffles(int nCards,int iCut);
Find the result of shuffles(1002,101)
any hints of the algorithm???
I know I can just do the algorithm over and over again until it becomes the original deck, however, there MUST be a much more elegant solution
any help?
TIA
EDIT: no this is NOT a HW problem