We now build on the shuffling methods of lab 1 to perform a card trick. You tell the audience your have a deck on N cards labeled 0 .. N-1. You ask the audience to choose any number between 1 and N-1. Whatever this number is, you will shuffle the deck until the top card is at that dept into the deck. Assuming you are capable of doing the inShuffle and the outShuffle, this trick wil be easy for you because you can place the top card of the deck into any position by performing a sequence of in and out shuffles.
The exact sequence of in/out shuffles is determined as follows. Suppose you have a deck of 20 card and the audience wants you to shuffle the top card to the 13th position in the deck. This means that your [0]th card (top) will move to [13]th position ([13] array index) in the deck. Take the number 13 and convert it to binary: i.e. 13 ==> 1101. Better yet, store it as String: "1101". Now going from left to right across that bitString and if you land on a 1 do an inShuffle. If you land on a 0 do a outShuffle. When you are done, the top card will be at index [13] in the deck (array).
java TopCardPlacer 18 13
(#cards placementIndex)