IntroductionSu Doku is a number puzzle which seems to have originated in 1979 but which from November 2004 has begun appearing on the puzzle pages of most newspapers and magazines.
The puzzle starts with a number of the squares already filled in - eg figure 2.
Your task is to fill in all the blank squares such that each row, each column and each 3x3 block with a thicker outline contains each of the digits from 1 to 9 only once, as in figure 3.
The difficulty of puzzles is rated from 'easy' to 'fiendish', partly determined by how many squares are filled in initially, usually from 40 down to 25, although the arrangement of the initial numbers also affects the difficulty. |
Su Doku on the hp 39g+ Graphing CalculatorSolving Su Doku puzzles is fiddly but can be done by accurately following a set of instructions and remembering pieces of information, and is therefore ideal for solving by a computer. |
Loading SuDokuCopy the files SUDOKU00.000, HP39DIR.000 and HP39DIR.CUR to an empty directory on a PC, start the HP39G Connectivity program and point it to the directory holding the three files. |
Running SuDokuRun SuDoku from the PROGRAM catalog. Once it has compiled its title appears on the screen and a 9x9 grid is drawn. You are then invited to enter the digits already supplied in the puzzle. The screen is shown in figure 4.
The 3x3 blocks have a solid border and the individual squares a dotted border. The current square is highlighted in solid black. The keys used to enter the digits are:
If the keys are pressed too rapidly the screen display may lag behind, but it should catch up if you pause. Obviously care is needed to type all the digits in the correct places, otherwise the wrong solution (or even no solution) will be found. The program has to perform some processing of the grid before it can begin solving, and the screen shown as figure 5 will appear for about a minute.
A small black square is gradually drawn on the left side of the screen to show progress. Next the message Solving... appears on the screen. The messages Singles:, Rows:, Columns: and 3x3s: will appear in turn. These refer to which groups of squares the solving algorithm is currently looking at and are just displayed to show that something is happening. A small 9x9 square is gradually drawn alongside the words to indicate which part of the main grid is being considered, and new digits are printed in the grid as they are deduced. See figure 6.
Generally more than one 'pass' through the grid will be needed to solve the puzzle and after each pass the word Finished? will briefly appear to the left of the grid while the program checks whether there are still any blank squares, then solving continues. For most puzzles, after a few minutes all the squares will have been filled in and a screen like figure 7 will be displayed, showing the full grid and the time in minutes taken to solve it. The display is 'frozen' at this point - pressing any key will return to the calculator's PROGRAM catalog.
The solution can be read from the screen and it is also stored in matrix M9, with the rows and columns as on the screen. For some puzzles rated as 'fiendish' the solving process reaches a stage where it is impossible to deduce a unique value for any square, just a choice of two or three possible values. The program's action in this situation is to find the blank square with the fewest 'possible' values, pick one at random, then continue solving using this value. A screen like figure 8 will appear while it is choosing a random digit.
If the guessed digit was wrong then the grid will at some later stage reach a state where there are no allowed digits for one or more blank squares because all the digits from 1 to 9 have already been used in the same row, column and 3x3 block. Hence after the program has resorted to guesswork it performs an extra check for this situation at the end of each 'pass', where it makes sure the grid is still in a Solvable? state. See figure 9.
If the grid does become impossible to solve this means the guessed digit was wrong and so the program reverts to the state the grid was in immediately before it guessed, and makes a new guess. Reverting to the stored grid takes a little time, during which the screen of figure 10 is shown.
If the puzzle is particularly difficult then guesses may need to be made more than once, and since they are unlikely to all be correct the first time the program may have to revert to its saved grid several times before the puzzle is solved. This is why 'fiendish' puzzles can take a while to solve. |
Hardware RequirementsSuDoku runs on a Hewlett-Packard 39g+ calculator. It should also work on the 39g and 40g but will take about three times as long to solve puzzles, due to the slower processor. It is written in HP-BASIC and may work on the 48g and 49g but has not been tried. The program takes up 5.2 kilobytes of RAM when first loaded, which expands to 17 kilobytes when run. It also uses 7.2 kilobytes to store matrices as part of the solving process, though most is recovered when the program exits. This means the calculator must have about 25 kilobytes of free RAM to run SuDoku. This, plus use of the DISPXY command, rules it out for the 38g model. |
SpeedDespite having a very fast (for a calculator) processor in the ARM 9, the BASIC on the hp 39g+ is disappointingly slow, even allowing for having to emulate the previous Saturn processor. As a result solving of Su Doku puzzles takes a little time. Exactly how long clearly depends on the difficulty of the puzzle but some typical times are:
|
Variables UsedSuDoku uses the following HOME variables, and will therefore overwrite any existing information stored in them:
|
Known BugsSuDoku has no way to check that the initial set of digits, before it begins solving, actually has a solution. If there is a mistake in the printed puzzle or in the digits you enter then SuDoku may loop forever trying to solve it. |