Question: (P8.1.3) Suppose we use a vector to represent a deck of n cards. We can cut the deck by taking n/2 cards from the middle
(P8.1.3) Suppose we use a vector to represent a deck of n cards. We can cut the deck by taking n/2 cards from the middle of the deck and putting this half-deck of cards on the top.
In MATLAB Complete the following function to perform this cut:
function sd = cu t ( d ) % Cut a deck o f c a r d s by moving h a l f t h e c a r d s from t h e m i d dle % t o t h e t o p . % d i s a v e c t o r whose l e n g t h i s a m u l t i p l e o f 4 . % sd i s t h e v e c t o r a f t e r c u t t i n g t h e deck d .
Write a script to find out whether the cards in a deck of 52 would cycle back to the original arrangement after repeated cuts as described above. If so, how many cuts are needed? Name your function file as cut.m and the script file to test cut as P813.m. Use vectorized operations instead of loops in function cut.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
