I'm not certain, but I'm fairly sure that this could be solved greedily. My solver is not super-fast but it can find a guaranteed optimal solution in no more than a couple minutes. Once we know which midpoint state is on the path to an optimal solution, the program can perform DFS using that midpoint state as a goal (and pruning any path that selects a square not in the midpoint.) Or, it might be feasible to just build up the paths in the BFS steps, at the cost of some additional memory. The other pruning technique which proved to be key to a fast solver is simply checking whether there are more than N colors left, if you are N or fewer steps away from the current best solution. (A heuristic applied to the order of the subtrees examined in the second step would probably help some, as well.) Both of these BFS searches can be pruned by eliminating states found in previous depths, and the latter search can be bounded by the depth of the best-known solution. Then, I examine each state at the midpoint depth and perform a new BFS starting with that as the root. The search strategy I took is to perform BFS up to a "midpoint" depth where the number of states would become infeasible, somewhere between 11 and 13 moves works best. (With a depth-first strategy it is therefore important to maintain a history to avoid a redundant work.) The effective branching factor seems closer to 3 than to 5. ![]() I observed that the search space actually grows much slower than the branching factor of the search tree, because there are quite a lot of duplicate positions. I took a slightly different approach because I was interested in finding the provably optimal path, not just a 'good' one. Combining a good heuristic with bounded DFS (or BFS with lookahead) results in solutions that are quite fast for the standard 14x14 grid. Heuristics look at the number of squares and distribution of colors left unchosen, or the distance to the "farthest away" square. Most of the solvers out there are heuristic and do not guarantee optimality. Continue using logic and deduction until you have filled in all of the empty squares.I have been working on this, and after I got my solver working I took a look at the approaches others had taken. Every Sudoku has one solution, so double check by making sure each column, row and square contains the numbers 1-9 with no duplicates or omissions. Next, you can start scanning each row for a certain number, like 1, to see where it should go. Then look for single empty squares in each row and column that you can fill in. If you see a single empty space in a larger square, fill that in first. For example, if a square already has 7 out of the 9 spaces filled in, you can figure out which 2 numbers are missing and use the numbers in the correlating rows and columns to determine which of the two missing numbers belongs in each space. Some squares already have numbers filled in, so begin by look for missing numbers in a row, column or square. To complete the grid, every column, row and square (each containing 9 spaces) needs to be filled in with the numbers 1-9 without repeating any numbers within the row, column or square. ![]() The grid is divided into 9 separate 3 x 3 squares. Sudoku is a game played on a 9 x 9 grid where the object of the game is to fill every space with the correct number.
0 Comments
Leave a Reply. |