If you take a deck of 2n playing cards, cut it into two stacks of n and interleave them, you have performed a perfect shuffle.
Example: for the six-card deck [1 2 3 4 5 6]T , the result is [4 1 5 2 6 3]T (note that the top card of the second stack goes on top. Write down the matrix A2n for a perfect shuffle of 2n cards when 2n=10 and 2n=12. How many times must you (perfectly) shuffle a deck of 10 cards to return it to its original order? (I.e., for what k is A10k=I?) How many for 12 cards? Take a guess at the numbers for a bridge deck of 52 and a Pinochle deck of 48.
*MATLAB or any Software Language may be used. Please show all work and explain thoroughly.
The language used is python. I have explained each step.
import itertools #for concatenating two lists
def perfectShuffle(deck): # the perfect shuffle function will
shuffle the deck of cards 'deck' one time
mid = len(deck) // 2 # finds the mid-way of the 'deck'
first_deck = deck[:mid] # divides the deck into the first
half
second_deck = deck[mid:] # similarly for second half
shuffle_list = list(zip(second_deck,first_deck)) # zip() is a
python function that will pair together two lists, for eg.
zip([4,5,6], [1,2,3]) = [(4, 1), (5, 2), (6, 3)]
shuffle = list(itertools.chain.from_iterable(shuffle_list)) # this
function will convert the above list to a single list
[4,1,5,2,6,3]
return shuffle
def countOfShuffles(start):
count = 1 # the counter will have the number of shuffles
required
end = perfectShuffle(start) # the first shuffle
while (start != end): # checking whether the deck is back to
original state
end = perfectShuffle(end) # if not shuffle again
count += 1
return count # return the count
def main():
A12 = list(range(1,13)) # for n = 6, 2n = 12 and A12 =
[1,2,3,4,5,6,7,8,9,10,11,12]
print (countOfShuffles(A12)) #calling the function
A10 = list(range(1,11))
print (countOfShuffles(A10))
A52 = list(range(1,53))
print (countOfShuffles(A52))
A48 = list(range(1,49))
print (countOfShuffles(A48))
if __name__ == "__main__":
main()
Code
Output
If you take a deck of 2n playing cards, cut it into two stacks of n and interleave them, you have...
If you take a deck of 2n playing cards, cut it into two stacks of n and interleave them, you have performed a perfect shuffle. Example: for the six-card deck [1 2 3 4 5 6]T , the result is [4 1 5 2 6 3]T (note that the top card of the second stack goes on top. Write down the matrix A2n for a perfect shuffle of 2n cards when 2n=10 and 2n=12. How many times must you (perfectly)...
5. Consider the following method of tacking playing cards off a table: If you only have one card, place the card so it is halfway over the table. If you have two cards, place the top card so that half of it is hanging over the second card, and the second card such that 1 of it is hanging over the table. If you have three cards, place the top card so that half of it is hanging over the...
Use inheritance and classes to represent a deck of playing cards. Create a Cardclass that stores the suit (e.g. Clubs, Diamonds, Hearts, Spades), and name (e.g. Ace, 2, 10, Jack) along with appropriate accessors, constructors, and mutators. Next, create a Deck class that stores a vector of Card objects. The default constructor should create objects that represent the standard 52 cards and store them in the vector. The Deck class should have functions to: • Print every card in the...
Play Your Cards Right Obtain a standard deck of 52 playing cards. Mix them well and count out 25 cards WITHOUT LOOKING AT THEM. Put aside the remaining cards. You are going to perform an experiment to estimate the probablity of drawing a club, a diamond, a heart, and a spade from your deck of 25 cards. A. Mix the 25 cards well Draw one card. Record its occurrence in the approprlate box. below B. Replace the card and shuffle...
3. You have a standard deck of 52 playing cards. There are two colors (black and red) and four suits (spades are black, clubs are black, hearts are red, and diamonds are red). Each suit has 13 cards, in which there is an ace, numbered cards from 2 to 10, and three face cards (jack, queen, and king) a. You randomly draw and then replace a card. What's the probability it's an ace? What's the probability it's the 4 of...
Sive Answer 29/1 points Consider the following experiment. You have a deck of 52 playing cards, with 4 kings. You shuffle the deck, draw out a card at random, and note whether it is a king or not. Without putting the card back, you repeat the process 9 more times (so, a total of 10 times. Suppose you wanted to find the probability of drawing out a king, is the binomial distribution appropriate for this situation, and why? Hint read...
You are dealt two cards successively (without replacement) from a shuffles deck of 52 playing cards. Find the probability that the first card is king and the second card is queen. 7. An IRS auditor randomly selects 3 tax returns from 58 tax returns of which 8 contain errors. What is the probability that she selects none of those containing errors? 8. 9. A sample of 4 different calculators is randomly selected from a group containing 47 that are defective...
Deck of Cards Program I need help printing a flush, which is showing the top 5 cards of the same suite. Below is the code I already have that answers other objectives, such as dealing the cards, and finding pairs. Towards the end I have attempted printing a flush, but I cannot figure it out. public class Shuffler { /** * The number of consecutive shuffle steps to be performed in each call * to each sorting...
While using JAVA , solve this. There are three basic classes we'll need this week: Card: A class like the one presented in the modules, but with a few changes. Hand: A class that represents the cards held by a single player. Deck: A class that represents the source of the cards for dealing and, as the game progresses, the place from which players can receive new cards (say, as they pick cards "from the deck" or when future hands...
hello there, i have to implement this on java processing. can someone please help me regarding that? thanks War is the name of a popular children’s card game. There are many variants. After playing War with a friend for over an hour, they argue that this game must never end . However! You are convinced that it will end. As a budding computer scientist, you decide to build a simulator to find out for sure! You will implement the logic...