Cody

Problem 44491. Shuffle

Solution 1558342

Submitted on 12 Jun 2018 by Lenny Gorodetsky
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
filetext = fileread('shuffle.m'); assert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')

2   Pass
v = [1, 2, 3, 4, 5, 6, 7, 8]; n = 1; w_correct = 8 : -1 : 1; assert(isequal(shuffle(v, n), w_correct))

vector = 1 2 3 4 5 6 7 tail = 8 z = 8 y = 1 i = 7 vector = 1 2 3 4 5 6 tail = 7 z = 8 7 y = 2 i = 6 vector = 1 2 3 4 5 tail = 6 z = 8 7 6 y = 3 i = 5 vector = 1 2 3 4 tail = 5 z = 8 7 6 5 y = 4 i = 4 vector = 1 2 3 tail = 4 z = 8 7 6 5 4 y = 5 i = 3 vector = 1 2 tail = 3 z = 8 7 6 5 4 3 y = 6 i = 2 vector = 1 tail = 2 z = 8 7 6 5 4 3 2 y = 7 i = 1 vector = 1×0 empty double row vector tail = 1 z = 8 7 6 5 4 3 2 1 y = 8 i = 0 cetvor = 8 7 6 5 4 3 2 1

3   Pass
v = [1; 2; 3; 4; 5; 6; 7; 8]; n = 2; w_correct = [7;8; 5;6; 3;4; 1;2]; assert(isequal(shuffle(v, n), w_correct))

vector = 1 2 3 4 5 6 tail = 7 8 z = 7 8 y = 2 i = 6 vector = 1 2 3 4 tail = 5 6 z = 7 8 5 6 y = 4 i = 4 vector = 1 2 tail = 3 4 z = 7 8 5 6 3 4 y = 6 i = 2 vector = 0×1 empty double column vector tail = 1 2 z = 7 8 5 6 3 4 1 2 y = 8 i = 0 cetvor = 7 8 5 6 3 4 1 2

4   Pass
v = [1, 2, 3, 4, 5, 6, 7, 8]; n = 3; w_correct = [6,7,8, 3,4,5, 1,2]; assert(isequal(shuffle(v, n), w_correct))

vector = 1 2 3 4 5 tail = 6 7 8 z = 6 7 8 y = 3 i = 5 vector = 1 2 tail = 3 4 5 z = 6 7 8 3 4 5 y = 6 i = 2 vector = 1×0 empty double row vector tail = 1 2 z = 6 7 8 3 4 5 1 2 y = 8 i = -1 cetvor = 6 7 8 3 4 5 1 2

5   Pass
v = [1; 2; 3; 4; 5; 6; 7; 8]; n = 4; w_correct = [5;6;7;8; 1;2;3;4]; assert(isequal(shuffle(v, n), w_correct))

vector = 1 2 3 4 tail = 5 6 7 8 z = 5 6 7 8 y = 4 i = 4 vector = 0×1 empty double column vector tail = 1 2 3 4 z = 5 6 7 8 1 2 3 4 y = 8 i = 0 cetvor = 5 6 7 8 1 2 3 4

6   Pass
v = [1, 2, 3, 4, 5, 6, 7, 8]; n = 5; w_correct = [4,5,6,7,8, 1,2,3]; assert(isequal(shuffle(v, n), w_correct))

vector = 1 2 3 tail = 4 5 6 7 8 z = 4 5 6 7 8 y = 5 i = 3 vector = 1×0 empty double row vector tail = 1 2 3 z = 4 5 6 7 8 1 2 3 y = 8 i = -2 cetvor = 4 5 6 7 8 1 2 3

7   Pass
v = [1; 2; 3; 4; 5; 6; 7; 8]; n = 6; w_correct = [3;4;5;6;7;8; 1;2]; assert(isequal(shuffle(v, n), w_correct))

vector = 1 2 tail = 3 4 5 6 7 8 z = 3 4 5 6 7 8 y = 6 i = 2 vector = 0×1 empty double column vector tail = 1 2 z = 3 4 5 6 7 8 1 2 y = 8 i = -4 cetvor = 3 4 5 6 7 8 1 2

8   Pass
v = [1, 2, 3, 4, 5, 6, 7, 8]; n = 7; w_correct = [2,3,4,5,6,7,8, 1]; assert(isequal(shuffle(v, n), w_correct))

vector = 1 tail = 2 3 4 5 6 7 8 z = 2 3 4 5 6 7 8 y = 7 i = 1 vector = 1×0 empty double row vector tail = 1 z = 2 3 4 5 6 7 8 1 y = 8 i = -6 cetvor = 2 3 4 5 6 7 8 1

9   Pass
v = [1; 2; 3; 4; 5; 6; 7; 8]; n = 8; w_correct = [1;2;3;4;5;6;7;8]; assert(isequal(shuffle(v, n), w_correct))

vector = 0×1 empty double column vector tail = 1 2 3 4 5 6 7 8 z = 1 2 3 4 5 6 7 8 y = 8 i = 0 cetvor = 1 2 3 4 5 6 7 8

10   Pass
v = [1, 2, 3, 4, 5, 6, 7, 8]; n = 9; w_correct = [1,2,3,4,5,6,7,8]; assert(isequal(shuffle(v, n), w_correct))

vector = 1×0 empty double row vector tail = 1 2 3 4 5 6 7 8 z = 1 2 3 4 5 6 7 8 y = 8 i = -1 cetvor = 1 2 3 4 5 6 7 8

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!