Cody

# Problem 44491. Shuffle

Solution 1414590

Submitted on 12 Jan 2018 by David Verrelli
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 shifty = 8 ans = 8 mishmash = 8 vector = 1 2 3 4 5 6 shifty = 7 ans = 8 7 mishmash = 8 7 vector = 1 2 3 4 5 shifty = 6 ans = 8 7 6 mishmash = 8 7 6 vector = 1 2 3 4 shifty = 5 ans = 8 7 6 5 mishmash = 8 7 6 5 vector = 1 2 3 shifty = 4 ans = 8 7 6 5 4 mishmash = 8 7 6 5 4 vector = 1 2 shifty = 3 ans = 8 7 6 5 4 3 mishmash = 8 7 6 5 4 3 vector = 1 shifty = 2 ans = 8 7 6 5 4 3 2 mishmash = 8 7 6 5 4 3 2 vector = 1×0 empty double row vector shifty = 1 ans = 8 7 6 5 4 3 2 1 mishmash = 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 shifty = 7 8 mishmash = 7 8 vector = 1 2 3 4 shifty = 5 6 mishmash = 7 8 5 6 vector = 1 2 shifty = 3 4 mishmash = 7 8 5 6 3 4 vector = 0×1 empty double column vector shifty = 1 2 mishmash = 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 shifty = 6 7 8 ans = 6 7 8 mishmash = 6 7 8 vector = 1 2 shifty = 3 4 5 ans = 6 7 8 3 4 5 mishmash = 6 7 8 3 4 5 vector = 1×0 empty double row vector shifty = 1 2 ans = 6 7 8 3 4 5 1 2 mishmash = 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 shifty = 5 6 7 8 mishmash = 5 6 7 8 vector = 0×1 empty double column vector shifty = 1 2 3 4 mishmash = 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 shifty = 4 5 6 7 8 ans = 4 5 6 7 8 mishmash = 4 5 6 7 8 vector = 1×0 empty double row vector shifty = 1 2 3 ans = 4 5 6 7 8 1 2 3 mishmash = 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 shifty = 3 4 5 6 7 8 mishmash = 3 4 5 6 7 8 vector = 0×1 empty double column vector shifty = 1 2 mishmash = 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 shifty = 2 3 4 5 6 7 8 ans = 2 3 4 5 6 7 8 mishmash = 2 3 4 5 6 7 8 vector = 1×0 empty double row vector shifty = 1 ans = 2 3 4 5 6 7 8 1 mishmash = 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 shifty = 1 2 3 4 5 6 7 8 mishmash = 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 shifty = 1 2 3 4 5 6 7 8 ans = 1 2 3 4 5 6 7 8 mishmash = 1 2 3 4 5 6 7 8