. QuickBASIC
QuickBASIC programs

    Analog Dial          ROCKET       GALCON    SUDOKU PROGRAMS    

Ver 4.3

A typical SUDOKU board is divided into nine grids of nine cells. The object of the game is to fill in all the cells with a number from 1 to 9, without a double in any grid, row or column. This program attempts to do just that, even if it has to try it over 10 million times!

SUDOKU solver screen after typing numbers in from a book.

The solved puzzle.

This early version of the program took over ten minutes to solve!
The program was originally named "Pseudo Sudoku Solver."
A later version solved it on a single pass.

This image shows how the "Grid1" subroutine works.
The program has two subroutines, named Grid0 and Grid1.

Grid0 begins by going through all the empty cells, making a list of all possible numbers for each cell. It looks in the 3X3 grid that contains the cell, then across the row and up and down the column. If the list has a single digit on it, it puts it in the cell. It scans the puzzle ten times. Each number that it finds increases the odds it will find another number.

It will sometimes solve the puzzle during this phase.

If the puzzle is not solved, Grid1 then starts in the top-left cell in the top-left grid. It finds the first available empty cell. It generates a random number, then looks within the grid for any numbers already there. It then looks at the row and the column. If a matching number is not found, it puts the number in the cell. If a matching number IS found, it generates a new number. The process repeats till all 81cells contain a number.

Both the cells and the grids are processed in this order, from 1 to 9:

When a grid is filled, the next grid is begun starting at the top-left cell. If a number can't be entered into a cell, the grid will start over. If the grid has been processed 30 times and still can't be completed, the whole board starts over.

Grid1 is mindless. A human can look at a grid and see that a "5" can be in one of two places in the same row. That means a 5 can't be in that row in the other two grids. The program has no such insight.

Grid1 doesn't have much of a memory! It doesn't "remember" that it placed a 5 in the first row of the second column. It's up to the other cells to "see" that there is a five there, as each one gets its turn. The only thing it "remembers" are the numbers that YOU have typed in.

I can't think of a more inefficient way to run a program. The program puts numbers into the cells, and the other cells have to look to see what numbers the program put there. Each cell has it's own programming. You can think of it as 81 sub-routines. This is probably a good example of how NOT to write a program.

I programmed the first cell for Grid1, then copied, pasted and edited it 80 more times. I did the same thing for Grid0. It was a bug factory, but once the bugs were out the program worked very well.

  Click on icon above to view or download source code   Click on icon above to download SUDOKU43.exe  

Note: Browsers don't like .EXE files.  Rename "SUDOKU43.RenameToExe" to "SUDOKU43.exe"

Version 4.3
Deleted 1050 lines of code by adding 9 subroutines. Will now load into QuickBASIC.

Version 4.1
Major logic flaw fixed. (program didn't rescan 3 X 3 grid after placing numbers, resulting in doubles.)
Several bug fixes. No longer fits in QuickBASIC. (DOH!)

Version 3.1
Pre-scan of cells. Y axis changed to letters instead of numbers. Some improvements to performance.

Version 2.0
Non working version. I attempted to fill the puzzle using digits in numerical order. it never got past number 5.

Version 1.7
2 bugs fixed.
Version 1.62
You can make unlimited changes while filling in the puzzle.
Some improvements to performance.

Version 1.4
You no longer need to press <ENTER> when entering numbers. Less tedious!

Version 1.3
Board is now white, other color fixes.
1 bug fix.

Version 1.2
Now runs in a resizable window.
Grid 1 runs more efficiently (Grid 1 gets hit every single time the Sudoku screen restarts.)
Will open in QuickBASIC 4.5 and QB64.
Asks if you want another puzzle.
1 bug fix.
Screens cleaned up.

Version 1.0
The nine grids started out as nine subroutines (Grid1 to Grid9). However, switching back and forth caused a Stack Overflow and the program would crash. All the subroutines were combined into one large sub. Unfortunately, it was too large to load into QuickBASIC 4.5 and would only load in QB64.
The board is supposed to be white, but it is grey. The program uses the BASIC text mode screen. Text mode doesn't support a white background.

July 2020