Problem 173. Minefield Sonar
Background
In mine-hunting games (e.g. Microsoft Minesweeper), the user is provided with a covered grid that, upon a left click, uncovers a hint as to the bombs around it or a bomb itself. The goal of this problem is to generate this grid based on the placement of a number of bombs and the puzzle size.
More information can be found on the Wikipedia page.
Description
You are provided with the row and column of K mines on a grid, I and J respectively, as well as the number of rows and columns on the grid, M and N respectively. Using this information, generate an M x N grid where the values on the grid represent the number of mines adjacent to that square or, if there is a mine on that particular square, the value -1.
Example
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers303
Suggested Problems
-
Calculate the Levenshtein distance between two strings
1506 Solvers
-
Given an unsigned integer x, find the largest y by rearranging the bits in x
1978 Solvers
-
Sum all integers from 1 to 2^n
17303 Solvers
-
Square Digits Number Chain Terminal Value (Inspired by Project Euler Problem 92)
249 Solvers
-
Side of an equilateral triangle
6841 Solvers
More from this Author56
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!