Matrices and grids · 13 / 15 Exercise Hard

Minesweeper

Objective

In minesweeper, each square without a mine shows how many mines there are in its up to 8 neighbouring squares. You must take care of the edges of the board.

Instructions

  • The first line has rows f and columns c; then come f lines of c characters, with * (mine) or . (empty).
  • Show the solved board: mines stay as * and each empty square is replaced by its number of neighbouring mines.
Input
3 3
*..
...
..*
Output
*10
121
01*

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise