Cody

Problem 44491. Shuffle

Solution 2391864

Submitted on 27 May 2020 by Shahar Kalfon
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))

v = 1 2 3 4 5 6 7 8 m = 1 cetvor = [] v1 = 1 2 3 4 5 6 7 8 o = 8 z = 7 q = 8 v = 1 2 3 4 5 6 7 w = 8 v = 1 2 3 4 5 6 7 m = 0 z = 0 v = 8 n = 1 cetvor = 8 v1 = 1 2 3 4 5 6 7 o = 7 z = 6 q = 7 v = 1 2 3 4 5 6 w = 7 v = 1 2 3 4 5 6 m = 1 z = 1 v = 8 7 n = 2 cetvor = 8 7 v1 = 1 2 3 4 5 6 o = 6 z = 5 q = 6 v = 1 2 3 4 5 w = 6 v = 1 2 3 4 5 m = 1 z = 2 v = 8 7 6 n = 3 cetvor = 8 7 6 v1 = 1 2 3 4 5 o = 5 z = 4 q = 5 v = 1 2 3 4 w = 5 v = 1 2 3 4 m = 1 z = 3 v = 8 7 6 5 n = 4 cetvor = 8 7 6 5 v1 = 1 2 3 4 o = 4 z = 3 q = 4 v = 1 2 3 w = 4 v = 1 2 3 m = 1 z = 4 v = 8 7 6 5 4 n = 5 cetvor = 8 7 6 5 4 v1 = 1 2 3 o = 3 z = 2 q = 3 v = 1 2 w = 3 v = 1 2 m = 1 z = 5 v = 8 7 6 5 4 3 n = 6 cetvor = 8 7 6 5 4 3 v1 = 1 2 o = 2 z = 1 q = 2 v = 1 w = 2 v = 1 m = 1 z = 6 v = 8 7 6 5 4 3 2 n = 7 cetvor = 8 7 6 5 4 3 2 v1 = 1 o = 1 ans = logical 1 w = 1 v = [] v = [] m = 1 z = 7 v = 8 7 6 5 4 3 2 1 n = 8 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))

v = 1 2 3 4 5 6 7 8 m = 8 v = 1 2 3 4 5 6 7 8 cetvor = [] v1 = 1 2 3 4 5 6 7 8 o = 8 z = 6 q = 7 v = 1 2 3 4 5 6 w = 7 8 v = 1 2 3 4 5 6 m = 0 z = 0 v = 7 8 n = 2 cetvor = 7 8 v1 = 1 2 3 4 5 6 o = 6 z = 4 q = 5 v = 1 2 3 4 w = 5 6 v = 1 2 3 4 m = 1 z = 2 v = 7 8 5 6 n = 4 cetvor = 7 8 5 6 v1 = 1 2 3 4 o = 4 z = 2 q = 3 v = 1 2 w = 3 4 v = 1 2 m = 1 z = 4 v = 7 8 5 6 3 4 n = 6 cetvor = 7 8 5 6 3 4 v1 = 1 2 o = 2 ans = logical 1 w = 1 2 v = [] v = [] m = 1 z = 6 v = 7 8 5 6 3 4 1 2 n = 8 cetvor = 7 8 5 6 3 4 1 2 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))

v = 1 2 3 4 5 6 7 8 m = 1 cetvor = [] v1 = 1 2 3 4 5 6 7 8 o = 8 z = 5 q = 6 v = 1 2 3 4 5 w = 6 7 8 v = 1 2 3 4 5 m = 0 z = 0 v = 6 7 8 n = 3 cetvor = 6 7 8 v1 = 1 2 3 4 5 o = 5 z = 2 q = 3 v = 1 2 w = 3 4 5 v = 1 2 m = 1 z = 3 v = 6 7 8 3 4 5 n = 6 cetvor = 6 7 8 3 4 5 v1 = 1 2 o = 2 ans = logical 1 w = 1 2 v = [] v = [] m = 1 z = 6 v = 6 7 8 3 4 5 1 2 n = 8 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))

v = 1 2 3 4 5 6 7 8 m = 8 v = 1 2 3 4 5 6 7 8 cetvor = [] v1 = 1 2 3 4 5 6 7 8 o = 8 z = 4 q = 5 v = 1 2 3 4 w = 5 6 7 8 v = 1 2 3 4 m = 0 z = 0 v = 5 6 7 8 n = 4 cetvor = 5 6 7 8 v1 = 1 2 3 4 o = 4 ans = logical 1 w = 1 2 3 4 v = [] v = [] m = 1 z = 4 v = 5 6 7 8 1 2 3 4 n = 8 cetvor = 5 6 7 8 1 2 3 4 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))

v = 1 2 3 4 5 6 7 8 m = 1 cetvor = [] v1 = 1 2 3 4 5 6 7 8 o = 8 z = 3 q = 4 v = 1 2 3 w = 4 5 6 7 8 v = 1 2 3 m = 0 z = 0 v = 4 5 6 7 8 n = 5 cetvor = 4 5 6 7 8 v1 = 1 2 3 o = 3 ans = logical 1 w = 1 2 3 v = [] v = [] m = 1 z = 5 v = 4 5 6 7 8 1 2 3 n = 8 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))

v = 1 2 3 4 5 6 7 8 m = 8 v = 1 2 3 4 5 6 7 8 cetvor = [] v1 = 1 2 3 4 5 6 7 8 o = 8 z = 2 q = 3 v = 1 2 w = 3 4 5 6 7 8 v = 1 2 m = 0 z = 0 v = 3 4 5 6 7 8 n = 6 cetvor = 3 4 5 6 7 8 v1 = 1 2 o = 2 ans = logical 1 w = 1 2 v = [] v = [] m = 1 z = 6 v = 3 4 5 6 7 8 1 2 n = 8 cetvor = 3 4 5 6 7 8 1 2 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))

v = 1 2 3 4 5 6 7 8 m = 1 cetvor = [] v1 = 1 2 3 4 5 6 7 8 o = 8 z = 1 q = 2 v = 1 w = 2 3 4 5 6 7 8 v = 1 m = 0 z = 0 v = 2 3 4 5 6 7 8 n = 7 cetvor = 2 3 4 5 6 7 8 v1 = 1 o = 1 ans = logical 1 w = 1 v = [] v = [] m = 1 z = 7 v = 2 3 4 5 6 7 8 1 n = 8 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))

v = 1 2 3 4 5 6 7 8 m = 8 v = 1 2 3 4 5 6 7 8 cetvor = [] v1 = 1 2 3 4 5 6 7 8 o = 8 ans = logical 1 w = 1 2 3 4 5 6 7 8 v = [] v = [] m = 0 z = 0 v = 1 2 3 4 5 6 7 8 n = 8 cetvor = 1 2 3 4 5 6 7 8 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))

v = 1 2 3 4 5 6 7 8 m = 1 cetvor = [] v1 = 1 2 3 4 5 6 7 8 o = 8 ans = logical 1 w = 1 2 3 4 5 6 7 8 v = [] v = [] m = 0 z = 0 v = 1 2 3 4 5 6 7 8 n = 8 cetvor = 1 2 3 4 5 6 7 8

Suggested Problems

More from this Author25

Community Treasure Hunt

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

Start Hunting!