Cody

# Problem 173. Minefield Sonar

Solution 2910949

Submitted on 4 Sep 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
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))

Index in position 1 is invalid. Array indices must be positive integers or logical values. Error in minehunting (line 6) y(i,j) = sum([y(i+1,j),y(i-1,j),y(i,j+1),y(i,j-1),y(i+1,j+1),y(i+1,j-1),y(i-1,j+1),y(i-1,j-1)] == -1) Error in Test1 (line 13) assert(isequal(minehunting(I,J,M,N),y_correct))

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

Index in position 1 is invalid. Array indices must be positive integers or logical values. Error in minehunting (line 6) y(i,j) = sum([y(i+1,j),y(i-1,j),y(i,j+1),y(i,j-1),y(i+1,j+1),y(i+1,j-1),y(i-1,j+1),y(i-1,j-1)] == -1) Error in Test2 (line 11) assert(isequal(minehunting(I,J,M,N),y_correct))

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

Index in position 1 is invalid. Array indices must be positive integers or logical values. Error in minehunting (line 6) y(i,j) = sum([y(i+1,j),y(i-1,j),y(i,j+1),y(i,j-1),y(i+1,j+1),y(i+1,j-1),y(i-1,j+1),y(i-1,j-1)] == -1) Error in Test3 (line 11) assert(isequal(minehunting(I,J,M,N),y_correct))

4   Fail
[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))

Index in position 1 is invalid. Array indices must be positive integers or logical values. Error in minehunting (line 6) y(i,j) = sum([y(i+1,j),y(i-1,j),y(i,j+1),y(i,j-1),y(i+1,j+1),y(i+1,j-1),y(i-1,j+1),y(i-1,j-1)] == -1) Error in Test4 (line 14) assert(isequal(minehunting(I,J,M,N),y_correct))

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

Index in position 1 is invalid. Array indices must be positive integers or logical values. Error in minehunting (line 6) y(i,j) = sum([y(i+1,j),y(i-1,j),y(i,j+1),y(i,j-1),y(i+1,j+1),y(i+1,j-1),y(i-1,j+1),y(i-1,j-1)] == -1) Error in Test5 (line 14) assert(isequal(minehunting(I,J,M,N),y_correct))

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!