'How can I implement an algorithm for a matrix where each cell can have one of two values, with hints

Firstly, sorry for the vagueness of the title.

I don't know if there is a name for this sort of algorithm.

I am interested in finding out how this scenario could be implemented.

Say I have a matrix (columns and rows) where each "cell" can have one of two values ("on" and "off").

Each cell's "background" should also display a number that tells how many of the adjacent cells are "on".

For example, if every cell should be "on":

A B C A B C
4 6 4 --> on on on
6 9 6 on on on
4 6 4 on on on

This is pretty simple to implement. The question is: what's the minimal amount of tips I can have, and how can I implement this?

In this same example, it would be enough to have:

A B C A B C
--> on on on
9 on on on
on on on

It can get trickier:

A B C A B C
--> on ? off
4 1 on ? off
on ? off

In this last example, the matrix would be larger and have other hints that later on would help determine the remaining cells.

So how can this be achieved?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source