Cody

Problem 2701. Go to the head of the class!

Solution 3011707

Submitted on 30 Sep 2020 by mohsen
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
m = magic(3); n = 9; y_correct=[9 2 4; 1 6 8; 5 7 3]; assert(isequal(me_first(m,n),y_correct));

r = 3 c = 2 x = 4 9 2 8 1 6 3 5 7 y = 9 2 4 1 6 8 5 7 3

2   Pass
m = magic(3); n = 15; y_correct=m; assert(isequal(me_first(m,n),y_correct));

r = 0×1 empty double column vector c = 0×1 empty double column vector

3   Pass
m=reshape(1:55,11,[]); n=42; y_correct=[42 53 9 20 31 43 54 10 21 32 44 55 11 22 33 34 45 1 12 23 35 46 2 13 24 36 47 3 14 25 37 48 4 15 26 38 49 5 16 27 39 50 6 17 28 40 51 7 18 29 41 52 8 19 30]; assert(isequal(me_first(m,n),y_correct));

r = 9 c = 4 x = 9 20 31 42 53 10 21 32 43 54 11 22 33 44 55 1 12 23 34 45 2 13 24 35 46 3 14 25 36 47 4 15 26 37 48 5 16 27 38 49 6 17 28 39 50 7 18 29 40 51 8 19 30 41 52 y = 42 53 9 20 31 43 54 10 21 32 44 55 11 22 33 34 45 1 12 23 35 46 2 13 24 36 47 3 14 25 37 48 4 15 26 38 49 5 16 27 39 50 6 17 28 40 51 7 18 29 41 52 8 19 30

4   Pass
m=reshape(1:64,8,[]) n=42; m(2)=42; y_correct=[42 10 18 26 34 42 50 58 3 11 19 27 35 43 51 59 4 12 20 28 36 44 52 60 5 13 21 29 37 45 53 61 6 14 22 30 38 46 54 62 7 15 23 31 39 47 55 63 8 16 24 32 40 48 56 64 1 9 17 25 33 41 49 57]; assert(isequal(me_first(m,n),y_correct));

m = 1 9 17 25 33 41 49 57 2 10 18 26 34 42 50 58 3 11 19 27 35 43 51 59 4 12 20 28 36 44 52 60 5 13 21 29 37 45 53 61 6 14 22 30 38 46 54 62 7 15 23 31 39 47 55 63 8 16 24 32 40 48 56 64 r = 2 2 c = 1 6 x = 42 10 18 26 34 42 50 58 3 11 19 27 35 43 51 59 4 12 20 28 36 44 52 60 5 13 21 29 37 45 53 61 6 14 22 30 38 46 54 62 7 15 23 31 39 47 55 63 8 16 24 32 40 48 56 64 1 9 17 25 33 41 49 57 y = 42 10 18 26 34 42 50 58 3 11 19 27 35 43 51 59 4 12 20 28 36 44 52 60 5 13 21 29 37 45 53 61 6 14 22 30 38 46 54 62 7 15 23 31 39 47 55 63 8 16 24 32 40 48 56 64 1 9 17 25 33 41 49 57

5   Pass
x=randi(9)+3; m=ones(x); n=4; assert(isequal(me_first(m,n),m));

r = 0×1 empty double column vector c = 0×1 empty double column vector

6   Pass
x=randi(9)+3; m=ones(x); j=m; m(randi(numel(m)))=x n=x; j(1)=x; assert(isequal(me_first(m,n),j));

m = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 r = 8 c = 9 x = 1 1 1 1 1 1 1 1 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 y = 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Suggested Problems

More from this Author80

Community Treasure Hunt

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

Start Hunting!