Question

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) 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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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
import itertools #for concatenating two lists def perfectShuffle(deck): one time # the perfect shuffle function will shuffle

def main() A12list (range(1,13)) # for n = 6, 2n #calling the function 12 and A12 = [1,2,3,4,5,6,7, print (countOfShuffles (A

Output

Python 3.6.1 (default, D ec 2015, 13: GCC 4. 8.21 on linux

Add a comment
Know the answer?
Add Answer to:
If you take a deck of 2n playing cards, cut it into two stacks of n and interleave them, you have...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT