Cody

# Problem 44350. Breaking Out of the Matrix

Solution 1680152

Submitted on 25 Nov 2018 by Will O'Connell
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))

Idx = 1 Idx = 2 Idx = 3 Idx = 4

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

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

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

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

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

Idx = 1

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

Idx = 1 Idx = 2 Idx = 3 Idx = 4 Idx = 5 Idx = 6 Idx = 7 Idx = 8 Idx = 9 Idx = 10 Idx = 11 Idx = 12 Idx = 13 Idx = 14 Idx = 15 Idx = 16 Idx = 17 Idx = 18 Idx = 19 Idx = 20 Idx = 21 Idx = 22 Idx = 23 Idx = 24 Idx = 25 Idx = 26 Idx = 27 Idx = 28 Idx = 29 Idx = 30 Idx = 31 Idx = 32 Idx = 33 Idx = 34 Idx = 35 Idx = 36 Idx = 37 Idx = 38 Idx = 39 Idx = 40 Idx = 41 Idx = 42 Idx = 43 Idx = 44 Idx = 45 Idx = 46 Idx = 47 Idx = 48 Idx = 49 Idx = 50 Idx = 51 Idx = 52 Idx = 53 Idx = 54 Idx = 55 Idx = 56 Idx = 57 Idx = 58 Idx = 59 Idx = 60 Idx = 61 Idx = 62 Idx = 63 Idx = 64 Idx = 65 Idx = 66 Idx = 67 Idx = 68 Idx = 69 Idx = 70 Idx = 71 Idx = 72 Idx = 73 Idx = 74 Idx = 75 Idx = 76 Idx = 77 Idx = 78 Idx = 79 Idx = 80 Idx = 81

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

Idx = 1