Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Solution 167509

Submitted on 24 Nov 2012 by Slobodan Ilic

Correct

133Size
Leading solution size is 48.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test
Code Input and Output
1
Pass
 
%%
a = [1 0; 0 0];
[r1,r2,c1,c2] = biggest_box(a);
sub = a(r1:r2,c1:c2);
[m,n] = size(sub);
len = 1;
assert(isequal(sum(sub(:)),0))
assert(isequal(m,len));
assert(isequal(n,len));
b =
     1
b =
     1     0
     0     0
b =
     0
b =
     0
b =
     0
2
Pass
 
%%
a = [1 0 0; 0 0 0; 0 0 0];
[r1,r2,c1,c2] = biggest_box(a);
sub = a(r1:r2,c1:c2);
[m,n] = size(sub);
len = 2;
assert(isequal(sum(sub(:)),0))
assert(isequal(m,len));
assert(isequal(n,len));
b =
     1
b =
     1     0
     0     0
b =
     1     0     0
     0     0     0
     0     0     0
b =
     0
b =
     0     0
     0     0
b =
     0
b =
     0
b =
     0     0
     0     0
b =
     0
b =
     0     0
     0     0
b =
     0
b =
     0
b =
     0
b =
     0
3
Pass
 
%%
a = eye(9);
[r1,r2,c1,c2] = biggest_box(a);
sub = a(r1:r2,c1:c2);
[m,n] = size(sub);
len = 4;
assert(isequal(sum(sub(:)),0))
assert(isequal(m,len));
assert(isequal(n,len));
b =
     1
b =
     1     0
     0     1
b =
     1     0     0
     0     1     0
     0     0     1
b =
     1     0     0     0
     0     1     0     0
     0     0     1     0
     0     0     0     1
b =
     1     0     0     0     0
     0     1     0     0     0
     0     0     1     0     0
     0     0     0     1     0
     0     0     0     0     1
b =
     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
b =
     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
b =
     1     0     0     0     0     0     0     0
     0     1     0     0     0     0     0     0
     0     0     1     0     0     0     0     0
     0     0     0     1     0     0     0     0
     0     0     0     0     1     0     0     0
     0     0     0     0     0     1     0     0
     0     0     0     0     0     0     1     0
     0     0     0     0     0     0     0     1
b =
     1     0     0     0     0     0     0     0     0
     0     1     0     0     0     0     0     0     0
     0     0     1     0     0     0     0     0     0
     0     0     0     1     0     0     0     0     0
     0     0     0     0     1     0     0     0     0
     0     0     0     0     0     1     0     0     0
     0     0     0     0     0     0     1     0     0
     0     0     0     0     0     0     0     1     0
     0     0     0     0     0     0     0     0     1
b =
     0
b =
     0     0
     1     0
b =
     0     0     0
     1     0     0
     0     1     0
b =
     0     0     0     0
     1     0     0     0
     0     1     0     0
     0     0     1     0
b =
     0     0     0     0     0
     1     0     0     0     0
     0     1     0     0     0
     0     0     1     0     0
     0     0     0     1     0
b =
     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
b =
     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     0
b =
     0     0     0     0     0     0     0     0
     1     0     0     0     0     0     0     0
     0     1     0     0     0     0     0     0
     0     0     1     0     0     0     0     0
     0     0     0     1     0     0     0     0
     0     0     0     0     1     0     0     0
     0     0     0     0     0     1     0     0
     0     0     0     0     0     0     1     0
b =
     0
b =
     0     0
     0     0
b =
     0     0     0
     0     0     0
     1     0     0
b =
     0     0     0     0
     0     0     0     0
     1     0     0     0
     0     1     0     0
b =
     0     0     0     0     0
     0     0     0     0     0
     1     0     0     0     0
     0     1     0     0     0
     0     0     1     0     0
b =
     0     0     0     0     0     0
     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
b =
     0     0     0     0     0     0     0
     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
b =
     0
b =
     0     0
     0     0
b =
     0     0     0
     0     0     0
     0     0     0
b =
     0     0     0     0
     0     0     0     0
     0     0     0     0
     1     0     0     0
b =
     0     0     0     0     0
     0     0     0     0     0
     0     0     0     0     0
     1     0     0     0     0
     0     1     0     0     0
b =
     0     0     0     0     0     0
     0     0     0     0     0     0
     0     0     0     0     0     0
     1     0     0     0     0     0
     0     1     0     0     0     0
     0     0     1     0     0     0
b =
     0
b =
     0     0
     0     0
b =
     0     0     0
     0     0     0
     0     0     0
b =
     0     0     0     0
     0     0     0     0
     0     0     0     0
     0     0     0     0
b =
     0     0     0     0     0
     0     0     0     0     0
     0     0     0     0     0
     0     0     0     0     0
     1     0     0     0     0
b =
     0
b =
     0     0
     0     0
b =
     0     0     0
     0     0     0
     0     0     0
b =
     0     0     0     0
     0     0     0     0
     0     0     0     0
     0     0     0     0
b =
     0
b =
     0     0
     0     0
b =
     0     0     0
     0     0     0
     0     0     0
b =
     0
b =
     0     0
     0     0
b =
     0
b =
     0
b =
     0     1
     0     0
b =
     0     1     0
     0     0     1
     0     0     0
b =
     0     1     0     0
     0     0     1     0
     0     0     0     1
     0     0     0     0
b =
     0     1     0     0     0
     0     0     1     0     0
     0     0     0     1     0
     0     0     0     0     1
     0     0     0     0     0
b =
     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
b =
     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
     0     0     0     0     0     0     0
b =
     0     1     0     0     0     0     0     0
     0     0     1     0     0     0     0     0
     0     0     0     1     0     0     0     0
     0     0     0     0     1     0     0     0
     0     0     0     0     0     1     0     0
     0     0     0     0     0     0     1     0
     0     0     0     0     0     0     0     1
     0     0     0     0     0     0     0     0
b =
     1
b =
     1     0
     0     1
b =
     1     0     0
     0     1     0
     0     0     1
b =
     1     0     0     0
     0     1     0     0
     0     0     1     0
     0     0     0     1
b =
     1     0     0     0     0
     0     1     0     0     0
     0     0     1     0     0
     0     0     0     1     0
     0     0     0     0     1
b =
     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
b =
     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
b =
     1     0     0     0     0     0     0     0
     0     1     0     0     0     0     0     0
     0     0     1     0     0     0     0     0
     0     0     0     1     0     0     0     0
     0     0     0     0     1     0     0     0
     0     0     0     0     0     1     0     0
     0     0     0     0     0     0     1     0
     0     0     0     0     0     0     0     1
b =
     0
b =
     0     0
     1     0
b =
     0     0     0
     1     0     0
     0     1     0
b =
     0     0     0     0
     1     0     0     0
     0     1     0     0
     0     0     1     0
b =
     0     0     0     0     0
     1     0     0     0     0
     0     1     0     0     0
     0     0     1     0     0
     0     0     0     1     0
b =
     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
b =
     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     0
b =
     0
b =
     0     0
     0     0
b =
     0     0     0
     0     0     0
     1     0     0
b =
     0     0     0     0
     0     0     0     0
     1     0     0     0
     0     1     0     0
b =
     0     0     0     0     0
     0     0     0     0     0
     1     0     0     0     0
     0     1     0     0     0
     0     0     1     0     0
b =
     0     0     0     0     0     0
     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
b =
     0
b =
     0     0
     0     0
b =
     0     0     0
     0     0     0
     0     0     0
b =
     0     0     0     0
     0     0     0     0
     0     0     0     0
     1     0     0     0
b =
     0     0     0     0     0
     0     0     0     0     0
     0     0     0     0     0
     1     0     0     0     0
     0     1     0     0     0
b =
     0
b =
     0     0
     0     0
b =
     0     0     0
     0     0     0
     0     0     0
b =
     0     0     0     0
     0     0     0     0
     0     0     0     0
     0     0     0     0
b =
     0
b =
     0     0
     0     0
b =
     0     0     0...
4
Pass
 
%%
a = double(magic(7)<6);
[r1,r2,c1,c2] = biggest_box(a);
sub = a(r1:r2,c1:c2);
[m,n] = size(sub);
len = 4;
assert(isequal(sum(sub(:)),0))
assert(isequal(m,len));
assert(isequal(n,len));
b =
     0
b =
     0     0
     0     0
b =
     0     0     0
     0     0     0
     0     0     0
b =
     0     0     0     1
     0     0     0     0
     0     0     0     0
     1     0     0     0
b =
     0     0     0     1     0
     0     0     0     0     0
     0     0     0     0     0
     1     0     0     0     0
     0     0     0     0     0
b =
     0     0     0     1     0     0
     0     0     0     0     0     0
     0     0     0     0     0     0
     1     0     0     0     0     0
     0     0     0     0     0     0
     0     0     0     0     0     1
b =
     0     0     0     1     0     0     0
     0     0     0     0     0     0     0
     0     0     0     0     0     0     0
     1     0     0     0     0     0     0
     0     0     0     0     0     0     1
     0     0     0     0     0     1     0
     0     0     0     0     1     0     0
b =
     0
b =
     0     0
     0     0
b =
     0     0     1
     0     0     0
     0     0     0
b =
     0     0     1     0
     0     0     0     0
     0     0     0     0
     0     0     0     0
b =
     0     0     1     0     0
     0     0     0     0     0
     0     0     0     0     0
     0     0     0     0     0
     0     0     0     0     0
b =
     0     0     1     0     0     0
     0     0     0     0     0     0
     0     0     0     0     0     0
     0     0     0     0     0     0
     0     0     0     0     0     1
     0     0     0     0     1     0
b =
     0
b =
     0     1
     0     0
b =
     0     1     0
     0     0     0
     0     0     0
b =
     0     1     0     0
     0     0     0     0
     0     0     0     0
     0     0     0     0
b =
     0     1     0     0     0
     0     0     0     0     0
     0     0     0     0     0
     0     0     0     0     0
     0     0     0     0     1
b =
     1
b =
     1     0
     0     0
b =
     1     0     0
     0     0     0
     0     0     0
b =
     1     0     0     0
     0     0     0     0
     0     0     0     0
     0     0     0     0
b =
     0
b =
     0     0
     0     0
b =
     0     0     0
     0     0     0
     0     0     0
b =
     0
b =
     0     0
     0     0
b =
     0
b =
     0
b =
     0     0
     0     0
b =
     0     0     0
     0     0     0
     1     0     0
b =
     0     0     0     0
     0     0     0     0
     1     0     0     0
     0     0     0     0
b =
     0     0     0     0     0
     0     0     0     0     0
     1     0     0     0     0
     0     0     0     0     0
     0     0     0     0     0
b =
     0     0     0     0     0     0
     0     0     0     0     0     0
     1     0     0     0     0     0
     0     0     0     0     0     0
     0     0     0     0     0     1
     0     0     0     0     1     0
b =
     0
b =
     0     0
     0     0
b =
     0     0     0
     0     0     0
     0     0     0
b =
     0     0     0     0
     0     0     0     0
     0     0     0     0
     0     0     0     0
b =
     0     0     0     0     0
     0     0     0     0     0
     0     0     0     0     0
     0     0     0     0     0
     0     0     0     0     1
b =
     0     0     0     0     0     0
     0     0     0     0     0     0
     0     0     0     0     0     0
     0     0     0     0     0     1
     0     0     0     0     1     0
     0     0     0     1     0     0
b =
     0
b =
     0     0
     0     0
b =
     0     0     0
     0     0     0
     0     0     0
b =
     0     0     0     0
     0     0     0     0
     0     0     0     0
     0     0     0     0
b =
     0     0     0     0     0
     0     0     0     0     0
     0     0     0     0     0
     0     0     0     0     1
     0     0     0     1     0
b =
     0
b =
     0     0
     0     0
b =
     0     0     0
     0     0     0
     0     0     0
b =
     0     0     0     0
     0     0     0     0
     0     0     0     0
     0     0     0     1
b =
     0
b =
     0     0
     0     0
b =
     0     0     0
     0     0     0
     0     0     0
b =
     0
b =
     0     0
     0     0
b =
     0
b =
     0
b =
     0     0
     1     0
b =
     0     0     0
     1     0     0
     0     0     0
b =
     0     0     0     0
     1     0     0     0
     0     0     0     0
     0     0     0     0
b =
     0     0     0     0     0
     1     0     0     0     0
     0     0     0     0     0
     0     0     0     0     0
     0     0     0     0     1
b =
     0
b =
     0     0
     0     0
b =
     0     0     0
     0     0     0
     0     0     0
b =
     0     0     0     0
     0     0     0     0
     0     0     0     0
     0     0     0     0
b =
     0     0     0     0     0
     0     0     0     0     0
     0     0     0     0     0
     0     0     0     0     1
     0     0     0     1     0
b =
     0
b =
     0     0
     0     0
b =
     0     0     0
     0     0     0
     0     0     0
b =
     0     0     0     0
     0     0     0     0
     0     0     0     0
     0     0     0     1
b =
     0     0     0     0     0
     0     0     0     0     0
     0     0     0     0     1
     0     0     0     1     0
     0     0     1     0     0
b =
     0
b =
     0     0
     0     0
b =
     0     0     0
     0     0     0
     0     0     0
b =
     0     0     0     0
     0     0     0     0
     0     0     0     1
     0     0     1     0
b =
     0
b =
     0     0
     0     0
b =
     0     0     0
     0     0     0
     0     0     1
b =
     0
b =
     0     0
     0     0
b =
     0
b =
     1
b =
     1     0
     0     0
b =
     1     0     0
     0     0     0
     0     0     0
b =
     1     0     0     0
     0     0     0     0
     0     0     0     0
     0     0     0     0
b =
     0
b =
     0     0
     0     0
b =
     0     0     0
     0     0     0
     0     0     0
b =
     0     0     0     0
     0     0     0     0
     0     0     0     0
     0     0     0     1
b =
     0
b =
     0     0
     0     0
b =
     0     0     0
     0     0     0
     0     0     0
b =
     0     0     0     0
     0     0     0     0
     0     0     0     1
     0     0     1     0
b =
     0
b =
     0     0
     0     0
b =
     0     0     0
     0     0     0
     0     0     1
b =
     0     0     0     0
     0     0     0     1
     0     0     1     0
     0     1     0     0
b =
     0
b =
     0     0
     0     0
b =
     0     0     0
     0     0     1
     0     1     0
b =
     0
b =
     0     0
     0     1
b =
     0
b =
     0
b =
     0     0
     0     0
b =
     0     0     0
     0     0     0
     0     0     0
b =
     0
b =
     0     0
     0     0
b =
     0     0     0
     0     0     0
     0     0     0
b =
     0
b =
     0     0
     0     0
b =
     0     0     0
     0     0     0
     0     0     1
b =
     0
b =
     0     0
     0     0
b =
     0     0     0
     0     0     1
     0     1     0
b =
     0
b =
     0     0
     0     1
b =
     0     0     1
     0     1     0
     1     0     0
b =
     0
b =
     0     1
     1     0
b =
     1
b =
     0
b =
     0     0
     0     0
b =
     0
b =
     0     0
     0     0
b =
     0
b =
     0     0
     0     0
b =
     0
b =
     0     0
     0     1
b =
     0
b =
     0     1
     1     0
b =
     1
b =
     1     0
     0     0
b =
     0
b =
     0
b =
     0
b =
     0
b =
     0
b =
     1
b =
     0
b =
     0