Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following the code segment that shuffles a deck of cards. the code

ID: 3867197 • Letter: C

Question

Consider the following the code segment that shuffles a deck of cards. the code so that the suits stay together. That is, shuffle the clubs, then shuffle the diamonds, then the hearts, and finally the spades. Therefore all the clubs are dealt first, then the diamond, etc. P = {[], [], []}: s = {'Clubs', 'Diamonds', 'Hearts', 'Spades'}: for c = 1: 52 card(c).suit = s{ceil(c/13)): card(c).val = mod(c, 13)+1: end x = 1: 52: for ii = 1: 100 c1 = randi ([1, 52)): c2 = randi ([1, 52]): t = x(c1): x(c1) x(c2): x(c2) = t: end for c = 1: 52 ii = mod (c, 4) + 1 p{ii} = [p{ii} card(x(c)))]: end

Explanation / Answer

p = {[],[],[],[]};

s = {'Clubs','Diamonds','Hearts','Spades'};

for c = 1:52

card(c).suit = s{ceil(c/13)};

card(c).val = mod(c,13)+1;

end

x=1:52;

for ii = 1:100

c1 = randi([1,13])

c2 = randi([1,13])

t = x(c1);

x(c1) = x(c2);

x(c2) = t;

c1 = randi([14,26])

c2 = randi([14,26])

t = x(c1);

x(c1) = x(c2);

x(c2) = t;

c1 = randi([27,39])

c2 = randi([27,39])

t = x(c1);

x(c1) = x(c2);

x(c2) = t;

c1 = randi([40,52])

c2 = randi([40,52])

t = x(c1);

x(c1) = x(c2);

x(c2) = t;

end

for c = 1:52

ii = ceil(c/13);

p{ii} = [p{ii} card(x(c))]

end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote