Cody

Solution 1346605

Submitted on 16 Nov 2017 by margreet docter
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))

sR = 2 sC = 2 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

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))))

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

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]))

sR = 6 sC = 6 X(:,:,1) = 1 0 0 1 X(:,:,2) = 0 1 0 0 X(:,:,3) = 0 0 0 0 X(:,:,4) = 0 0 0 0 X(:,:,5) = 0 0 0 0 X(:,:,6) = 0 0 0 0 X(:,:,7) = 0 0 1 0 X(:,:,8) = 1 0 0 1 X(:,:,9) = 0 1 0 0 X(:,:,10) = 0 0 0 0 X(:,:,11) = 0 0 0 0 X(:,:,12) = 0 0 0 0 X(:,:,13) = 0 0 0 0 X(:,:,14) = 0 0 1 0 X(:,:,15) = 1 0 0 1 X(:,:,16) = 0 1 0 0 X(:,:,17) = 0 0 0 0 X(:,:,18) = 0 0 0 0 X(:,:,19) = 0 0 0 0 X(:,:,20) = 0 0 0 0 X(:,:,21) = 0 0 1 0 X(:,:,22) = 1 0 0 1 X(:,:,23) = 0 1 0 0 X(:,:,24) = 0 0 0 0 X(:,:,25) = 0 0 0 0 X(:,:,26) = 0 0 0 0 X(:,:,27) = 0 0 0 0 X(:,:,28) = 0 0 1 0 X(:,:,29) = 1 0 0 1 X(:,:,30) = 0 1 0 0 X(:,:,31) = 0 0 0 0 X(:,:,32) = 0 0 0 0 X(:,:,33) = 0 0 0 0 X(:,:,34) = 0 0 0 0 X(:,:,35) = 0 0 1 0 X(:,:,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))

sR = 1 sC = 1 X = 93 108 123 138 153 168 1 16 31 46 61 76 91 107 122 137 152 167 13 15 30 45 60 75 90 92 121 136 151 166 12 14 29 44 59 74 89 104 106 135 150 165 11 26 28 43 58 73 88 103 105 120 149 164 10 25 27 42 57 72 87 102 117 119 134 163 9 24 39 41 56 71 86 101 116 118 133 148 8 23 38 40 55 70 85 100 115 130 132 147 162 22 37 52 54 69 84 99 114 129 131 146 161 7 36 51 53 68 83 98 113 128 143 145 160 6 21 50 65 67 82 97 112 127 142 144 159 5 20 35 64 66 81 96 111 126 141 156 158 4 19 34 49 78 80 95 110 125 140 155 157 3 18 33 48 63 79 94 109 124 139 154 169 2 17 32 47 62 77

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),ones(2)),1:size(M,3))))

sR = 5 sC = 5 X(:,:,1) = 1 1 1 1 X(:,:,2) = 1 1 1 1 X(:,:,3) = 1 1 1 1 X(:,:,4) = 1 1 1 1 X(:,:,5) = 1 1 1 1 X(:,:,6) = 1 1 1 1 X(:,:,7) = 1 1 1 1 X(:,:,8) = 1 1 1 1 X(:,:,9) = 1 1 1 1 X(:,:,10) = 1 1 1 1 X(:,:,11) = 1 1 1 1 X(:,:,12) = 1 1 1 1 X(:,:,13) = 1 1 1 1 X(:,:,14) = 1 1 1 1 X(:,:,15) = 1 1 1 1 X(:,:,16) = 1 1 1 1 X(:,:,17) = 1 1 1 1 X(:,:,18) = 1 1 1 1 X(:,:,19) = 1 1 1 1 X(:,:,20) = 1 1 1 1 X(:,:,21) = 1 1 1 1 X(:,:,22) = 1 1 1 1 X(:,:,23) = 1 1 1 1 X(:,:,24) = 1 1 1 1 X(:,:,25) = 1 1 1 1

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

sR = 1 sC = 1 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