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 70303

Submitted on 4 Apr 2012 by Kate

Correct

272Size
Leading solution size is 29.
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
 
%%
I = [ 2 3 3 5 1 4 9 2 3 9 ];
J = [ 1 1 4 4 5 5 6 8 8 9 ];
M = 9; N = 9;
y_correct = [  1  1  0  1 -1  1  1  1  1
              -1  2  1  2  2  1  2 -1  2
              -1  2  1 -1  2  1  2 -1  2
               1  1  2  3 -1  1  1  1  1
               0  0  1 -1  2  1  0  0  0
               0  0  1  1  1  0  0  0  0
               0  0  0  0  0  0  0  0  0
               0  0  0  0  1  1  1  1  1
               0  0  0  0  1 -1  1  1 -1 ];
assert(isequal(minehunting(I,J,M,N),y_correct))
minemask =
     2     3    30    32    37    40    54    65    66    81
y =
     0     0     0     0    -1     0     1     0     0
    -1     0     1     0     0     0     1    -1     0
    -1     0     0     0     0     0     0    -1     0
     0     0     1     0    -1     0     0     0     0
     0     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     0     1     0     0     1     0
     0     0     0     0     0    -1     0     0    -1
y =
     1     0     0     0    -1     0     1     1     0
     0     0     1     1     0     0     1     0     0
    -1     0     0     0     1     0     0    -1     0
     0     0     1     1    -1     0     0     0     0
     0     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     0     1     1     0     1     1
     0     0     0     0     0    -1     0     0    -1
y =
     1     0     0     1    -1     0     1     1     0
     0     0     1     1     0     0     2     0     0
    -1     0     1     0     1     0     1    -1     0
     0     0     1     2    -1     0     0     0     0
     0     0     1    -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     0     1     1     0     1     1
     0     0     0     0     1    -1     0     1    -1
y =
     1     0     0     1    -1     0     1     1     0
     0     0     1     1     0     1     2     0     0
    -1     1     1     0     1     0     1    -1     1
     0     1     1     2     0     0     0     0     1
     0     0     1    -1     0     1     0     0     0
     0     0     0     0     1     0     0     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     1     1     0     1     1
     0     0     0     0     1    -1     0     1    -1
y =
     1     0     0     1    -1     0     1     1     0
     0     0     1     1     1     1     2     0     0
     0     1     1     0     1     0     1     0     1
     1     1     1     3     0     0     0     1     1
     0     0     1    -1     1     1     0     0     0
     0     0     0     1     1     0     0     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     1     1     0     1     1
     0     0     0     0     1    -1     0     1    -1
y =
     1     0     0     1    -1     1     1     1     0
     0     1     1     1     1     1     2     0     1
     0     2     1     0     2     0     1     0     2
     1     1     1     3     0     1     0     1     1
     0     0     1    -1     2     1     0     0     0
     0     0     0     1     1     0     0     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     1     1     0     1     1
     0     0     0     0     1    -1     1     1    -1
y =
     1     1     0     1    -1     1     1     1     1
     0     2     1     1     2     1     2     0     2
     0     2     1     0     2     1     1     0     2
     1     1     1     3     1     1     0     1     1
     0     0     1    -1     2     1     0     0     0
     0     0     0     1     1     0     0     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     1     1     1     1     1
     0     0     0     0     1    -1     1     1    -1
y =
     1     1     0     1    -1     1     1     1     1
     0     2     1     2     2     1     2     0     2
     0     2     1     0     2     1     2     0     2
     1     1     2     3     1     1     1     1     1
     0     0     1     0     2     1     0     0     0
     0     0     1     1     1     0     0     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     1     1     1     1     1
     0     0     0     0     1    -1     1     1    -1
y =
     1     1     0     1    -1     1     1     1     1
    -1     2     1     2     2     1     2    -1     2
    -1     2     1    -1     2     1     2    -1     2
     1     1     2     3    -1     1     1     1     1
     0     0     1    -1     2     1     0     0     0
     0     0     1     1     1     0     0     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     1     1     1     1     1
     0     0     0     0     1    -1     1     1    -1
2
Pass
 
%%
I = 9; J = 9; M = 9; N = 9;
y_correct = [ 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  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  0  0
              0  0  0  0  0  0  0  0  0
              0  0  0  0  0  0  0  1  1
              0  0  0  0  0  0  0  1 -1 ];
assert(isequal(minehunting(I,J,M,N),y_correct))
minemask =
    81
y =
     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     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     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     0     0     0    -1
y =
     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     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     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     1     1
     0     0     0     0     0     0     0     0    -1
y =
     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     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     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     1     1
     0     0     0     0     0     0     0     1    -1
y =
     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     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     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     1     1
     0     0     0     0     0     0     0     1    -1
y =
     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     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     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     1     1
     0     0     0     0     0     0     0     1    -1
y =
     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     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     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     1     1
     0     0     0     0     0     0     0     1    -1
y =
     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     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     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     1     1
     0     0     0     0     0     0     0     1    -1
y =
     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     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     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     1     1
     0     0     0     0     0     0     0     1    -1
y =
     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     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     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     1     1
     0     0     0     0     0     0     0     1    -1
3
Pass
 
%%
I = 5; J = 5; M = 9; N = 9;
y_correct = [ 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  0
              0  0  0  1  1  1  0  0  0
              0  0  0  1 -1  1  0  0  0
              0  0  0  1  1  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  0  0  0  0 ];
assert(isequal(minehunting(I,J,M,N),y_correct))
minemask =
    41
y =
     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     0
     0     0     0     1     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     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0
y =
     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     0
     0     0     0     1     1     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     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0
y =
     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     0
     0     0     0     1     1     0     0     0     0
     0     0     0     1    -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     0     0     0     0     0
     0     0     0     0     0     0     0     0     0
y =
     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     0
     0     0     0     1     1     0     0     0     0
     0     0     0     1    -1     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     0     0     0     0     0
     0     0     0     0     0     0     0     0     0
y =
     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     0
     0     0     0     1     1     0     0     0     0
     0     0     0     1    -1     0     0     0     0
     0     0     0     0     1     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     0     0     0     0
y =
     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     0
     0     0     0     1     1     0     0     0     0
     0     0     0     1    -1     1     0     0     0
     0     0     0     0     1     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     0     0     0     0
y =
     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     0
     0     0     0     1     1     1     0     0     0
     0     0     0     1    -1     1     0     0     0
     0     0     0     0     1     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     0     0     0     0
y =
     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     0
     0     0     0     1     1     1     0     0     0
     0     0     0     1    -1     1     0     0     0
     0     0     0     1     1     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     0     0     0     0
y =
     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     0
     0     0     0     1     1     1     0     0     0
     0     0     0     1    -1     1     0     0     0
     0     0     0     1     1     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     0     0     0     0
4
Pass
 
%%
[I,J] = ndgrid(1:2:11,1:2:5);
M = 11; N = 5;
y_correct = [ -1  2 -1  2 -1
               2  4  2  4  2
              -1  2 -1  2 -1
               2  4  2  4  2
              -1  2 -1  2 -1
               2  4  2  4  2
              -1  2 -1  2 -1
               2  4  2  4  2
              -1  2 -1  2 -1
               2  4  2  4  2
              -1  2 -1  2 -1 ];
assert(isequal(minehunting(I,J,M,N),y_correct))
minemask =
     1    23    45
     3    25    47
     5    27    49
     7    29    51
     9    31    53
    11    33    55
y =
    -1     0    -1     0    -1
     0     1     0     1     0
    -1     0    -1     0    -1
     0     1     0     1     0
    -1     0    -1     0    -1
     0     1     0     1     0
    -1     0    -1     0    -1
     0     1     0     1     0
    -1     0    -1     0    -1
     0     1     0     1     0
    -1     0    -1     0    -1
y =
    -1     0    -1     0    -1
     1     1     1     1     1
    -1     0    -1     0    -1
     1     1     1     1     1
    -1     0    -1     0    -1
     1     1     1     1     1
    -1     0    -1     0    -1
     1     1     1     1     1
    -1     0    -1     0    -1
     1     1     1     1     1
    -1     0    -1     0    -1
y =
    -1     1    -1     1    -1
     1     1     1     1     1
    -1     1    -1     1    -1
     1     1     1     1     1
    -1     1    -1     1    -1
     1     1     1     1     1
    -1     1    -1     1    -1
     1     1     1     1     1
    -1     1    -1     1    -1
     1     1     1     1     1
    -1     1    -1     1    -1
y =
    -1     1    -1     1    -1
     1     2     1     2     1
    -1     1    -1     1    -1
     1     2     1     2     1
    -1     1    -1     1    -1
     1     2     1     2     1
    -1     1    -1     1    -1
     1     2     1     2     1
    -1     1    -1     1    -1
     1     2     1     2     1
    -1     1    -1     1    -1
y =
    -1     1    -1     1    -1
     2     2     2     2     2
    -1     1    -1     1    -1
     2     2     2     2     2
    -1     1    -1     1    -1
     2     2     2     2     2
    -1     1    -1     1    -1
     2     2     2     2     2
    -1     1    -1     1    -1
     2     2     2     2     2
    -1     1    -1     1    -1
y =
    -1     2    -1     2    -1
     2     2     2     2     2
    -1     2    -1     2    -1
     2     2     2     2     2
    -1     2    -1     2    -1
     2     2     2     2     2
    -1     2    -1     2    -1
     2     2     2     2     2
    -1     2    -1     2    -1
     2     2     2     2     2
    -1     2    -1     2    -1
y =
    -1     2    -1     2    -1
     2     3     2     3     2
    -1     2    -1     2    -1
     2     3     2     3     2
    -1     2    -1     2    -1
     2     3     2     3     2
    -1     2    -1     2    -1
     2     3     2     3     2
    -1     2    -1     2    -1
     2     3     2     3     2
    -1     2    -1     2    -1
y =
    -1     2    -1     2    -1
     2     4     2     4     2
    -1     2    -1     2    -1
     2     4     2     4     2
    -1     2    -1     2    -1
     2     4     2     4     2
    -1     2    -1     2    -1
     2     4     2     4     2
    -1     2    -1     2    -1
     2     4     2     4     2
    -1     2    -1     2    -1
y =
    -1     2    -1     2    -1
     2     4     2     4     2
    -1     2    -1     2    -1
     2     4     2     4     2
    -1     2    -1     2    -1
     2     4     2     4     2
    -1     2    -1     2    -1
     2     4     2     4     2
    -1     2    -1     2    -1
     2     4     2     4     2
    -1     2    -1     2    -1
5
Pass
 
%%
[I,J] = ndgrid(2:3:11,2:3:5);
M = 11; N = 5;
y_correct = [ 1  1  1  1  1
              1 -1  1  1 -1
              1  1  1  1  1
              1  1  1  1  1
              1 -1  1  1 -1
              1  1  1  1  1
              1  1  1  1  1
              1 -1  1  1 -1
              1  1  1  1  1
              1  1  1  1  1
              1 -1  1  1 -1 ];
assert(isequal(minehunting(I,J,M,N),y_correct))
minemask =
    13    46
    16    49
    19    52
    22    55
y =
     1     0     0     1     0
     0    -1     0     0    -1
     0     0     0     0     0
     1     0     0     1     0
     0    -1     0     0    -1
     0     0     0     0     0
     1     0     0     1     0
     0    -1     0     0    -1
     0     0     0     0     0
     1     0     0     1     0
     0    -1     0     0    -1
y =
     1     1     0     1     1
     0    -1     0     0    -1
     0     0     0     0     0
     1     1     0     1     1
     0    -1     0     0    -1
     0     0     0     0     0
     1     1     0     1     1
     0    -1     0     0    -1
     0     0     0     0     0
     1     1     0     1     1
     0    -1     0     0    -1
y =
     1     1     0     1     1
     1    -1     0     1    -1
     0     0     0     0     0
     1     1     0     1     1
     1    -1     0     1    -1
     0     0     0     0     0
     1     1     0     1     1
     1    -1     0     1    -1
     0     0     0     0     0
     1     1     0     1     1
     1    -1     0     1    -1
y =
     1     1     0     1     1
     1    -1     0     1    -1
     0     0     1     0     0
     1     1     0     1     1
     1    -1     0     1    -1
     0     0     1     0     0
     1     1     0     1     1
     1    -1     0     1    -1
     0     0     1     0     0
     1     1     0     1     1
     1    -1     0     1    -1
y =
     1     1     0     1     1
     1    -1     0     1    -1
     0     1     1     0     1
     1     1     0     1     1
     1    -1     0     1    -1
     0     1     1     0     1
     1     1     0     1     1
     1    -1     0     1    -1
     0     1     1     0     1
     1     1     0     1     1
     1    -1     0     1    -1
y =
     1     1     0     1     1
     1    -1     1     1    -1
     0     1     1     0     1
     1     1     0     1     1
     1    -1     1     1    -1
     0     1     1     0     1
     1     1     0     1     1
     1    -1     1     1    -1
     0     1     1     0     1
     1     1     0     1     1
     1    -1     1     1    -1
y =
     1     1     1     1     1
     1    -1     1     1    -1
     0     1     1     0     1
     1     1     1     1     1
     1    -1     1     1    -1
     0     1     1     0     1
     1     1     1     1     1
     1    -1     1     1    -1
     0     1     1     0     1
     1     1     1     1     1
     1    -1     1     1    -1
y =
     1     1     1     1     1
     1    -1     1     1    -1
     1     1     1     1     1
     1     1     1     1     1
     1    -1     1     1    -1
     1     1     1     1     1
     1     1     1     1     1
     1    -1     1     1    -1
     1     1     1     1     1
     1     1     1     1     1
     1    -1     1     1    -1
y =
     1     1     1     1     1
     1    -1     1     1    -1
     1     1     1     1     1
     1     1     1     1     1
     1    -1     1     1    -1
     1     1     1     1     1
     1     1     1     1     1
     1    -1     1     1    -1
     1     1     1     1     1
     1     1     1     1     1
     1    -1     1     1    -1