Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA PROJECT 2. One way to shuffle playing cards is to use a perfect shuffle. First, you divide a deck of 52 cards into two

image text in transcribedJAVA PROJECT

2. One way to shuffle playing cards is to use a perfect shuffle. First, you divide a deck of 52 cards into two halves of 26 cards each. Next, you merge the halves by interleaving the cards as follows. Beginning with the top half and alternating halves, you take the bottom card from a half and place it on top of a new deck. For example, if our deck contains the six cards 1 2 3 4 5 6, the top half is 1 2 3, and the bottom half is 4 5 6. The 3 at the bottom of the top half becomes the bottom card in the shuffled deck. We then place the 6, which is at the bottom of the bottom half, on top of the shuffled deck. Next, we place 2 on top, then 5, 1, and finally 4. The shuffled deck is then 4 1 5 2 6 3. Notice that the card that was on top of the original deck is now second in the shuffled result, and the bottom card in the original deck is now second from the bottom in the shuffled deck. This shuffle is called an in-shuffle and is achieved by beginning with the top half when you move cards into the shuffled result. If you begin with the bottom half, you get an out-shuffle, whereby the original top card and bottom card remain in their positions in the shuffled deck. Define a class of playing-card decks by using a deque to contain the cards. Your class should define methods to perform perfect in-shuffles and perfect out-shuffles. Using your class, 1. Determine the number of perfect out-shuffles needed to return a deck of n cards to its original order. 2. Determine the number of perfect in-shuffles needed to return a deck of n cards to its original order. c. You can move a deck's top card, which is at position 0, to any desired position m by performing a sequence of in-shuffles and out-shuffles, as follows. You write m in binary. Beginning with the leftmost 1 and proceeding to the right, you perform an in-shuffle for each 1 encountered and an out-shuffle for each O. For example, if m is 8, we have 1000 for its binary equivalent. We would perform one in- shuffle followed by three out-shuffles to move the original top card to position 8, that is, so it is the ninth card from the top of the deck. Define a method to perform this card trick

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Refactoring Databases Evolutionary Database Design

Authors: Scott Ambler, Pramod Sadalage

1st Edition

0321774515, 978-0321774514

More Books

Students also viewed these Databases questions

Question

Where does a drum-buffer-rope system work best?

Answered: 1 week ago