Your goal is to check whether a completed Minesweeper board is valid. This means that each number is a correct count of mines in cells adjacent to it, including diagonals. The board does not wrap around.
As usual, you should give a function or program, and shortest code in bytes wins.
See also past challenges to generate, solve, and fully implement Minesweeper.
Input:
A single string like this: 02X2 13X2 X211
.
The rows of the minesweeper board are given separated by spaces. So, the above represents the 3x4 board:
02X2
13X2
X211
Each cell is a character:
X
for a mine, or a number0
through8
.All rows have the same length.
There are at least 3 rows and 3 columns.
The input doesn't start or end with a space, but you may include a newline at the end if you wish.
Output:
A consistent Truthy on correct boards, and a consistent Falsey value on incorrect boards. Consistent means that all Truthy outputs are the same and all Falsey outputs are the same.
Test cases
Each line is a separate test case.
True
:
02X2 13X2 X211
XXXX XXXX XXXX XXXX
XX4X2 5X6X4 XX6XX 4XX54 2X4XX
False
:
02X2 13X2 X212
XXXX XXXX X7XX XXXX
XX5X2 5X6X4 XX6XX 4XX54 2X5XX