Cody

Solution 2003177

Submitted on 5 Nov 2019 by Tung Nguyen
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=[1 4 7 10; 2 5 8 11; 3 6 9 12]; R=2;C=3; X(:,:,1) =[1 4 7 ; 2 5 8]; X(:,:,2) =[2 5 8 ; 3 6 9]; X(:,:,3) =[4 7 10 ; 5 8 11]; X(:,:,4) =[5 8 11 ; 6 9 12]; assert(isequal(BreakTheMatrix(M,R,C),X))

X = 1 4 7 2 5 8 X = 2 5 8 3 6 9 X = 4 7 10 5 8 11 X = 5 8 11 6 9 12 y(:,:,1) = 1 4 7 2 5 8 y(:,:,2) = 2 5 8 3 6 9 y(:,:,3) = 4 7 10 5 8 11 y(:,:,4) = 5 8 11 6 9 12

2   Pass
x=1:ceil(35+25*rand());r=1;c=1; M=BreakTheMatrix(x,r,c); assert(all(arrayfun(@(y) (M(:,:,y)==y),1:numel(x))))

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

3   Pass
x=eye(7);r=2;c=2; M=BreakTheMatrix(x,r,c); ids=[1 8 15 22 29 36]; urs=ids(1:5)+1; lls=urs+5; z=setxor(1:size(M,3),[ids urs lls]); a1=arrayfun(@(a) isequal(M(:,:,a),eye(2)),ids); a2=arrayfun(@(a) isequal(M(:,:,a),[0 1 ; 0 0]),urs); a3=arrayfun(@(a) isequal(M(:,:,a),[0 0 ; 1 0]),lls); a4=arrayfun(@(a) isequal(M(:,:,a),zeros(2)),z); assert(all([a1 a2 a3 a4]))

X = 1 0 0 1 X = 0 1 0 0 X = 0 0 0 0 X = 0 0 0 0 X = 0 0 0 0 X = 0 0 0 0 X = 0 0 1 0 X = 1 0 0 1 X = 0 1 0 0 X = 0 0 0 0 X = 0 0 0 0 X = 0 0 0 0 X = 0 0 0 0 X = 0 0 1 0 X = 1 0 0 1 X = 0 1 0 0 X = 0 0 0 0 X = 0 0 0 0 X = 0 0 0 0 X = 0 0 0 0 X = 0 0 1 0 X = 1 0 0 1 X = 0 1 0 0 X = 0 0 0 0 X = 0 0 0 0 X = 0 0 0 0 X = 0 0 0 0 X = 0 0 1 0 X = 1 0 0 1 X = 0 1 0 0 X = 0 0 0 0 X = 0 0 0 0 X = 0 0 0 0 X = 0 0 0 0 X = 0 0 1 0 X = 1 0 0 1 y(:,:,1) = 1 0 0 1 y(:,:,2) = 0 1 0 0 y(:,:,3) = 0 0 0 0 y(:,:,4) = 0 0 0 0 y(:,:,5) = 0 0 0 0 y(:,:,6) = 0 0 0 0 y(:,:,7) = 0 0 1 0 y(:,:,8) = 1 0 0 1 y(:,:,9) = 0 1 0 0 y(:,:,10) = 0 0 0 0 y(:,:,11) = 0 0 0 0 y(:,:,12) = 0 0 0 0 y(:,:,13) = 0 0 0 0 y(:,:,14) = 0 0 1 0 y(:,:,15) = 1 0 0 1 y(:,:,16) = 0 1 0 0 y(:,:,17) = 0 0 0 0 y(:,:,18) = 0 0 0 0 y(:,:,19) = 0 0 0 0 y(:,:,20) = 0 0 0 0 y(:,:,21) = 0 0 1 0 y(:,:,22) = 1 0 0 1 y(:,:,23) = 0 1 0 0 y(:,:,24) = 0 0 0 0 y(:,:,25) = 0 0 0 0 y(:,:,26) = 0 0 0 0 y(:,:,27) = 0 0 0 0 y(:,:,28) = 0 0 1 0 y(:,:,29) = 1 0 0 1 y(:,:,30) = 0 1 0 0 y(:,:,31) = 0 0 0 0 y(:,:,32) = 0 0 0 0 y(:,:,33) = 0 0 0 0 y(:,:,34) = 0 0 0 0 y(:,:,35) = 0 0 1 0 y(:,:,36) = 1 0 0 1

4   Pass
u=ceil(10*rand())+4; x=magic(u);r=u;c=u; M=BreakTheMatrix(x,r,c); assert(isequal(M,x))

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

5   Pass
temp=ceil(8*rand)+3; x=ones(temp);r=2;c=2; M=BreakTheMatrix(x,r,c); assert(size(M,3)==(temp-1)^2); assert(all(arrayfun(@(a) isequal(M(:,:,a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= 1 1 1 1 y(:,:,8) = 1 1 1 1 y(:,:,9) = 1 1 1 1 y(:,:,10) = 1 1 1 1 y(:,:,11) = 1 1 1 1 y(:,:,12) = 1 1 1 1 y(:,:,13) = 1 1 1 1 y(:,:,14) = 1 1 1 1 y(:,:,15) = 1 1 1 1 y(:,:,16) = 1 1 1 1 y(:,:,17) = 1 1 1 1 y(:,:,18) = 1 1 1 1 y(:,:,19) = 1 1 1 1 y(:,:,20) = 1 1 1 1 y(:,:,21) = 1 1 1 1 y(:,:,22) = 1 1 1 1 y(:,:,23) = 1 1 1 1 y(:,:,24) = 1 1 1 1 y(:,:,25) = 1 1 1 1 y(:,:,26) = 1 1 1 1 y(:,:,27) = 1 1 1 1 y(:,:,28) = 1 1 1 1 y(:,:,29) = 1 1 1 1 y(:,:,30) = 1 1 1 1 y(:,:,31) = 1 1 1 1 y(:,:,32) = 1 1 1 1 y(:,:,33) = 1 1 1 1 y(:,:,34) = 1 1 1 1 y(:,:,35) = 1 1 1 1 y(:,:,36) = 1 1 1 1 y(:,:,37) = 1 1 1 1 y(:,:,38) = 1 1 1 1 y(:,:,39) = 1 1 1 1 y(:,:,40) = 1 1 1 1 y(:,:,41) = 1 1 1 1 y(:,:,42) = 1 1 1 1 y(:,:,43) = 1 1 1 1 y(:,:,44) = 1 1 1 1 y(:,:,45) = 1 1 1 1 y(:,:,46) = 1 1 1 1 y(:,:,47) = 1 1 1 1 y(:,:,48) = 1 1 1 1 y(:,:,49) = 1 1 1 1 y(:,:,50) = 1 1 1 1 y(:,:,51) = 1 1 1 1 y(:,:,52) = 1 1 1 1 y(:,:,53) = 1 1 1 1 y(:,:,54) = 1 1 1 1 y(:,:,55) = 1 1 1 1 y(:,:,56) = 1 1 1 1 y(:,:,57) = 1 1 1 1 y(:,:,58) = 1 1 1 1 y(:,:,59) = 1 1 1 1 y(:,:,60) = 1 1 1 1 y(:,:,61) = 1 1 1 1 y(:,:,62) = 1 1 1 1 y(:,:,63) = 1 1 1 1 y(:,:,64) = 1 1 1 1 y(:,:,65) = 1 1 1 1 y(:,:,66) = 1 1 1 1 y(:,:,67) = 1 1 1 1 y(:,:,68) = 1 1 1 1 y(:,:,69) = 1 1 1 1 y(:,:,70) = 1 1 1 1 y(:,:,71) = 1 1 1 1 y(:,:,72) = 1 1 1 1 y(:,:,73) = 1 1 1 1 y(:,:,74) = 1 1 1 1 y(:,:,75) = 1 1 1 1 y(:,:,76) = 1 1 1 1 y(:,:,77) = 1 1 1 1 y(:,:,78) = 1 1 1 1 y(:,:,79) = 1 1 1 1 y(:,:,80) = 1 1 1 1 y(:,:,81) = 1 1 1 1

6   Pass
x=eye(7);r=7;c=7; assert(isequal(x,BreakTheMatrix(x,r,c)))

X = 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 y = 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1

Suggested Problems

More from this Author80