Asked by:
Sudoku Challenge in Small Basic
General discussion

We already have some Sudoku Solvers written in Small Basic.
This challenge is to write Sudoku puzzle generator in Small Basic. Let's try!
See Also
 Sudoku Solver CGW786
 Sudoku Solver Text Ver. XCC382
 Sudoku Solver Graphics Ver. KFT913
 Chaos Sudoku Solver PTX661
Nonki Takahashi
 Edited by Nonki TakahashiModerator Friday, June 28, 2019 7:25 AM wrong id
All replies

This is my first step: RQM589.
This program is just a Sudoku UI. You can hit arrow keys (or click) to select a cell. And hit number keys, [Back Space] or [Delete] to set/reset a number.
Usage:
 Set numbers to initialize puzzle yourself.
 Push [Solve] key to start solving yourself.
 Set numbers to solve the puzzle.
 Push [New] key to clear all numbers.
Nonki Takahashi
 Edited by Nonki TakahashiModerator Wednesday, June 19, 2019 2:41 PM a


This is a simple idea to generate Sudoku puzzle: FJJ051. This idea fills random number from top left to bottom right. But random number is selected from candidate numbers that are updated with filled numbers. If there is no candidate, it restarts from the first. Following text is a sample output of this program. The left side means the generated puzzle and the right side means remaining candidates as 9 bit hexadecimal (0001FF).
7 9 6 1 5 3 2 8 4 004 001 008 100 010 040 080 002 020 3 8 1 7 4 2 9 5 6 040 002 100 004 020 080 001 010 008 4 5 2 9 6 8 7 3 1 020 010 080 001 008 002 004 040 100 9 3 8 2 1 4 5 6 7 001 040 002 080 100 020 010 008 004 6 7 5 3 8 9 1 4 2 008 004 010 040 002 001 100 020 080 1 2 4 5 7 6 8 9 3 100 080 020 010 004 008 002 001 040 5 6 9 4 2 7 3 1 8 010 008 001 020 080 004 040 100 002 8 1 7 6 3 5 4 2 9 002 100 004 008 040 010 020 080 001 2 4 3 8 9 1 6 7 080 020 040 002 001 100 008 004 010 i = 81 row = 9 col = 9 n = 5 7 9 6 1 5 3 2 8 4 004 001 008 100 010 040 080 002 020 3 8 1 7 4 2 9 5 6 040 002 100 004 020 080 001 010 008 4 5 2 9 6 8 7 3 1 020 010 080 001 008 002 004 040 100 9 3 8 2 1 4 5 6 7 001 040 002 080 100 020 010 008 004 6 7 5 3 8 9 1 4 2 008 004 010 040 002 001 100 020 080 1 2 4 5 7 6 8 9 3 100 080 020 010 004 008 002 001 040 5 6 9 4 2 7 3 1 8 010 008 001 020 080 004 040 100 002 8 1 7 6 3 5 4 2 9 002 100 004 008 040 010 020 080 001 2 4 3 8 9 1 6 7 5 080 020 040 002 001 100 008 004 010 Press any key to continue...
This method is slow. So I'd like to improve the performance.
Nonki Takahashi
 Edited by Nonki TakahashiModerator Wednesday, June 26, 2019 2:07 PM typo

We already have some Sudoku Solvers written in Small Basic.
This challenge is to write Sudoku puzzle generator in Small Basic. Let's try!
See Also
 Sudoku Solver CGW786
 Sudoku Solver Text Ver. XCC382
 Sudoku Solver Graphics Ver. KFT931
 Chaos Sudoku Solver PTX661
Nonki Takahashi
KFT931 does not import. wrong id? 


My rough idea to generate Sudoku puzzle is:
 Generate a Sudoku solution.
 Randomly remove a number from the board.
 Run Sudoku solver to the new board.
 If solved, repeat from step 2.
 If not solved, restore last removed number.
This algorithm needs a Sudoku solver. So I wrote it: GXT523.
Nonki Takahashi
 Edited by Nonki TakahashiModerator Saturday, August 17, 2019 9:45 AM hint

 Edited by Nonki TakahashiModerator Wednesday, August 21, 2019 4:50 AM program ID

The fourth step: NTS3000.
 You can solve the puzzle with number keys, arrow keys and Delete or Back Space key.
 You can toggle note with Ctrl + number keys.
 [Next] button is for next puzzle.
 No reaction when you solved...
 There is no hidden pair check in SS_ReservedPair().
Nonki Takahashi

I found a good site to understand how to solve Sudoku.
Angus Johnson's stepbystep guide to solving Sudoku (2005)Nonki Takahashi