Saturday, November 16, 2013

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.

Example if  nCards=9 and ICut=6 then for  N=123456789 , you need 3 shuffle to get the original positions , wondering how , try it now and  feel free to post comment here .

1 comment :

lalu said...

what is its actually doing will you explain ?

min(minInsert(a[1:]),minInsert(a[:-1])) ??