Jerry's Blog  1.5.001
mi propio
next article: Ode to Sudoku
Version 3
Sudoku Analyzer v. 3.0 released
Wed October 7 2020  2:29pmSudoku

When you press the buttons 'Analyze', 'Hint', 'Peek', or 'Solve', the Sudoku Analyzer sends a small Ajax packet to the server. The 'X' in A.J.A.X. in this case stands for 'executable', a program that runs on the hosting server at cyberjerry.info as a native BSD excutable or binary. The binary performs the requested task and sends another small packet back to your computer to complete the Ajax transaction. This program is written in C and assembly, compiled on the server using gcc, for maximum execution speed. (Sudoku analysis would run way too slowly in a scripting language.) The original and core part of the program, written in assembly, solves the Sudoku by means of simple and fast bitwise AND, OR, and XOR instructions in tightly coded repetitive loops. Its task is to solve the Sudoku grid, or exhaust all possibilities in trying to solve it. Upon finding one solution, it continues to repetitively loop, looking for additional solutions. It can thus report back to the C program whether the particular grid has one solution, multiple solutions, or no solution. Its secondary task is to construct the array used to make the Elimination Grid.

This simple but efficient assembly solver routine could (almost always) perform its task very quickly. Given an empty or nearly empty grid, even the fastest binary program would take too much time to try all possibilities, but it could continue to generate multiple solutions (as many as a million or more per second) until the calling C program said, "Enough!". When given a grid with several cells filled in and therefore fewer cells to solve, it could exhaust all possibilities in exponentially less time. Where it would take several days to find all the solutions for an empty grid, it could do the same in a couple seconds - less than one second on a fast web server - for a grid that had 60 or fewer empty cells. It could then report definitively to the C program that the grid had exactly one solution, multiple solutions, or no solution. The C program could then use this information to begin to analyze the grid and, in the case of a single solution Sudoku, could help the human operator with step by step hints. Thus was born the Sudoku Analyzer.

The middle range was a bit problematic, where the grid had between 8 and 20 cells filled in. Depending upon how the 8 to 20 cells were configured, they might in some cases prevent the assembly routine from generating solutions quickly. At the same time, so many unsolved cells meant that the assembly routine would repetitively loop exponentially more times trying to exhaust all possibilities, and the server would likely kill the program for taking too much processor time. None of the problematic grids tested were valid single-solution Sudokus; they either had no solution or multiple solutions. Or so I thought. So, a few years ago, to avoid the server timeout error, I added a loop counter, telling the assembly routine to quit if it had found no solution after 120 million loops, at which point the C program would report that the grid had "no solution, or too many to analyze."

This assembly solver routine has been the focus of my attention for the past several weeks. Written about 15 years ago, it was the first part of what eventually became the online Sudoku Analyzer. In the interim years I continued to make improvements and fix bugs in the interactive web page, and the server-side C program's analysis and hint logic, but the assembly routine remained mostly unchanged. Then, as noted in the previous blog article, Señor Manuel Navarro De La Hoz of Colombia sent me something I had never found: a single-solution Sudoku with only 17 cells filled in. For the reasons mentioned above, my assembly routine could not solve it nor exhaust all possibilities within the loop limit constraints. And I knew what I had to do: I had to go back to the beginning, and make the assembly language solver routine run smarter and faster.

The new assembly routine is more complex and more analytical than the old one. Rather than trying to solve every grid the same simple way, it examines the grid and ranks its unsolved cells and groups of cells according their possible valid contents. Similarly, rather than always trying the digits 1 through 9 in numerical order, it ranks the digits in an order more likely to produce valid results quickly. Finally, upon testing my new logic, it became apparent that extending the loop limit beyond a few million loops had very little impact. So my new routine tries to complete its work in under 8 million loops. If it fails, it might try a different order of digits and cells, then another, then another. 99.77% of the time it now does all its work with less than 20,000 loops, and should never make more than 20 million loops, even in worst cases, so the server should never complain that it is consuming too much processor time.

Since the above involves radical changes to the core assembly routine, this marks a major new release number for the Sudoku Analyzer, version 3.0.000. At this same version level, there are a few minor changes to the C portion of the server-side binary and to the client-side interface. One new feature you may notice is that, above the Elimination Grid, you may now click 'Stats' to see how many loops and how much time the binary is taking each time it is called. The overall Ajax time is there for reference; the new changes affect only the speed and efficiency of the server-side binary. I have no control over the Ajax process, which depends upon your connection speed and that of all the servers that pass the small Ajax packet back and forth between your computer and the server at cyberjerry.info.

Now, with all due respect to Señor Navarro, and with humble gratitude for his astute and successful answer to my Challenge, I am in no way relinquishing my Sudoku Analyzer's claim to be the best on the web. It was already the best, and now, thanks to Señor Navarro, it is even better. The website where he found the Sudoku that had my Analyzer (temporarily) stumped was nothing more than a collection of canned Sudoku grids and their final solutions. No step by step hints, no analysis, nothing.

As I compose this blog article, am also running a program on my home computer to generate Sudokus in various configurations of filled and empty cells, to continue testing my new logic. At this moment, this program has generated around 90 million grids, all of which the new logic is handling without failing, and without taking too much time. That's not to say that the Sudoku Analyzer is now without flaws, nor that 3.0.000 will be its final version. But if you find a problem, or if you ever come across another analyzer that performs like my Sudoku Analyzer, be sure to let me know.

  
previous article: Successful Challenger

0 comments:


 
He who at 20 is not a socialist has no heart.
He who at 30 is a socialist has no head.
- Dorothy Day

Articles
All  
Faith/Philosophy
Sudoku
Computer
Misc.
Copyright (c) 2017-2025 Gerald DePyper - Jinotega, Nicaragua, C.A.
rev. 2025.05.24