Besides narrowing down the number of solutions by 9!*5184 (as opposed to 9!*72 by the other method), I think are other reasons why this approach may be faster.

One of the things to note is that if the digits 1-8 have been placed, then there is one and only one way to place the 9's, giving a valid grid. So there are only 7 steps to make (place 2,3,..,8) before finding a solution.

Another thing is that after, say, the 1's and 2's have been placed, we care only which squares have been used, not which digits are in which squares. That is, a 12 above a 21 counts the same as a 21 above a 12. The data structure that would be used then, is something to store the board (maybe boolean of length 81) plus an integer storing the number of ways to get to that specific board state - and this would have to be stored in, say, a binary tree for easy searching ("has this board state been reached before?"). This would cut down on the speed of the program, at the expense of added storage.

(How much will it cut down the speed? I don't know. I looked at one random completed Sudoku grid and found 19 instances of the "12 above a 21" phenomenon. Note that if we have fixed where the 1's go, then there is no saving when placing the 2's. But there is a little with placing the 3's. My guess is that at least ~1/8 of those diagrams are repeats. This fraction would increase greatly when placing the 4's. How much storage is required? I don't know.)

I am not the most gifted programmer and thus am not sure whether I can implement the method in the preceeding paragraphs. However, I can do the naive brute-forcing, and the first step of finding the ~2000*7 possible fillings for the digits 2,3,...,8. If anyone sees promise with this method and would like to help, I would appreciate it.

Brian

Anonymous wrote:My guess: 2.8 x 10^25.

Given any digit, there are (3!)^6 = 46656 ways of filling the grid satisfying the rules. Given a filling with one digit and a filling with another, the probability that the two fillings are compatible is roughly (8/9)^9 = 34.6% (in each of the nine boxes we check that the two digits aren't in the same square).

Now, we choose a filling for all nine digits, (46656)^9 possible ways. The probability that these fillings are compatible is (.346)^36 (since there are (9 choose 2) = 36 choices of pairs of digits to check compatibility). Multiplying these two numbers yields the answer of 2.8 x 10^25.

This, of course, is a rough estimate, as I have assumed a lot of independence that is not true. But I think it is a reasonable guess.

Has anyone tried this method using a computer? That is, filling in all the 1's first, then filling in the 2's, and so on, rather than filling the upper left box with 1-9, then the upper middle box, and so on?

We may assume (by multiplying by 9! afterwards) that the upper left box is 123, 456, 789, which cuts down the possible fillings to 46656/9 = 5184 for each digit. Furthermore, we may choose exactly where the 1's go (by later multiplying by 5184). Then we eliminate the fillings for the digits 2,3,... that aren't compatible with the filling of 1's, leaving about (8/9)^8 * 5184 = 2000 possible fillings for each digit. With an explicit list of the 46656 possible fillings, it is simple to check whether two fillings are compatible (just list the squares the digits occupy and see whether any are the same).

Is this a practical method?