Interesting. But there seems to be a problem. I downloaded your notebook and evaluated graphHints, sudokuSolve and puzzle. But running sudokuSolve[puzzle] does not give a solution. Many error messages. At the beginning:
At end:
You can try evaluating the puzzle again. I tried it in a new notebook, and it seems to be working. Please let me know if you still encounter any errors.
Sorry, still same problem. Earlier, before my first post, I tried on two different PC“s and also in Wolfram Cloud. Same negative result on all three platforms.
For your info my PC“s has MMA v13.3. One is on Windows 11, the other on Windows 10.
Yes, you are right! I encountered the same error in the cloud. Please try running it again. I believe the error occurred due to a pair of parentheses that got deleted during the conversion of the blog. Iāve reorganized the code to use fewer parentheses and edit it in the blog and the comment. Thank you so much for catching that! Please let me know if it works now or if you encounter any other issues!
ā you have earned Featured Contributor Badge ![]()
Your exceptional post has been selected for our editorial column Staff Picks http://wolfr.am/StaffPicks and Your Profile is now distinguished by a Featured Contributor Badge and is displayed on the Featured Contributor Board. Thank you!
It works just fine now. I have tried it out on some of my previously solved Sudokus. Your method is quite fast, also in (traditionally) difficult cases!
Well, it turns out that this graph method is not yet without flaws. If a digit 1 to 9 is missing from the hints it will also be missing from the solution, with errors thrown. Try these hint matrices:
hintsA={
{0,0,0,0,0,4,1,8,2},{0,0,0,0,0,0,0,0,5},{8,0,0,0,0,9,0,0,0},
{2,0,4,1,0,0,0,0,0},{0,0,0,0,0,0,7,0,4},{0,0,0,0,0,0,3,2,0},
{0,0,0,7,0,8,4,0,0},{7,0,3,4,0,0,0,1,0},{5,0,0,0,2,1,0,0,9}
};
hintsB={
{9,8,0,0,0,0,0,0,3},{3,0,0,0,0,0,0,0,0},{0,0,0,0,7,0,0,0,0},
{0,0,0,0,0,0,0,2,8},{6,0,2,8,0,0,7,9,0},{0,5,0,0,0,0,0,0,0},
{0,7,8,3,0,5,2,0,0},{0,0,4,0,0,0,0,6,5},{0,0,0,0,0,4,0,8,0}
};
This is a nice follow-up to your previous post , especially because DepthFirstSearch doesnāt lead to a timely solution. However, itās well-known that Sudoku is a good use case for Donald Knuthās DancingLinksX algorithm, so itās also possible to compare times with FindExactCover. Using the MRV-heuristic, we can achieve a 2\times speed-up solving the puzzle as an exact cover problem. There is a debug-Reap with the WFR, which says that the solution here takes only 68 steps to fill in the 55 missing values, but I would have to read the source code again to see exactly what counts as a āstepā. If another semi-random heuristic is used, the step count explodes to more than 15K.
Regarding plausible submissions for the games book, this could be even better than the queenās problem, but again, to fit with the multi-computational theme, we need more information about whatās going on under-the-hood. In concrete terms, that means printing (ideally) a graph of the search tree explaining how a particular path is found through the space of all possibilities.
Code is here:
Thanks a lot for noticing that flaw! I have just corrected it, and hopefully, everything itās working correctly now!
Nice post, Iām also interested in Graph Theory methods for solving magic squares and Latin squares.


