Cody

Problem 44350. Breaking Out of the Matrix

Solution 2737588

Submitted on 24 Jul 2020
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   Fail
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))

y = 4 7 5 8

Assertion failed.

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

Error using arrayfun Non-scalar in Uniform output, at index 1, output 1. Set 'UniformOutput' to false. Error in Test2 (line 3) assert(all(arrayfun(@(y) (M(:,:,y)==y),1:numel(x))))

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

y = 0 1

Index in position 3 exceeds array bounds (must not exceed 3). Error in Test3>@(a)isequal(M(:,:,a),eye(2)) (line 7) a1=arrayfun(@(a) isequal(M(:,:,a),eye(2)),ids); Error in Test3 (line 7) a1=arrayfun(@(a) isequal(M(:,:,a),eye(2)),ids);

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

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

Index in position 1 exceeds array bounds (must not exceed 14). Error in BreakTheMatrix (line 6) y(:,:,i) = M(i:R+i-1,2:C) Error in Test4 (line 3) M=BreakTheMatrix(x,r,c);

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

y = 1 1

Assertion failed.

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

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

Index in position 1 exceeds array bounds (must not exceed 7). Error in BreakTheMatrix (line 6) y(:,:,i) = M(i:R+i-1,2:C) Error in Test6 (line 2) assert(isequal(x,BreakTheMatrix(x,r,c)))