This is a good answer. I changed the test suite so that you wouldn't have to deal with logical input matrices. Sorry about that!
This code is referenced in the following blog post: http://blogs.mathworks.com/community/2015/01/19/robot-game-playing-in-matlab-part-2/
Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
%%
a = [ 1 0 0 0 0
0 0 0 1 0
0 0 0 0 1
0 0 0 0 1
0 0 1 0 0 ];
tf = false;
assert(isequal(has_rectangle(a),tf))
|
2 | Pass |
%%
a = [ 1 0 1 0
0 0 1 0
1 0 1 0
0 0 1 1 ];
tf = true;
assert(isequal(has_rectangle(a),tf))
|
3 | Pass |
%%
a = [ 1 0 1 0
0 0 1 1
0 0 1 1 ];
tf = true;
assert(isequal(has_rectangle(a),tf))
|
4 | Pass |
%%
a = [ 1 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 1 0
1 0 0 0 0 0 0 1 0 ];
tf = true;
assert(isequal(has_rectangle(a),tf))
|
5 | Pass |
%%
a = zeros(20);
tf = false;
assert(isequal(has_rectangle(a),tf))
|
6 | Pass |
%%
a = ones(9);
tf = true;
assert(isequal(has_rectangle(a),tf))
|
7 | Pass |
%%
a = double(magic(6)<9);
tf = false;
assert(isequal(has_rectangle(a),tf))
|
1594 Solvers
Test if a Number is a Palindrome without using any String Operations
157 Solvers
Find the sum of the elements in the "second" diagonal
879 Solvers
Get the elements of diagonal and antidiagonal for any m-by-n matrix
196 Solvers
181 Solvers