There is a simple recursive solution to your problem, which is an example of a type of brute force called backtracking (google that).
(, fill_next) . , , , ( ), ; . , , 0 99, , , , .
: find_next , ; , fill_next (0). 0 8, 9 . 2D-, num% 3 num/3 .
, , , , .