Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Sudoku Engine Help
- EDGE_X
-
100+ posts
Sudoku Engine Help
Making a Sudoku 2x2 Project on Scratch but I will need a little help with the engine to lay out a possible puzzle, detect for wrong numbers and a proper way to randomize the number. Anyone want to help me?
I will give you credit for the engine in Notes and Credits and will also use it for 2x3, 3x3, 3x4 and 4x4 Sudokus.
I will give you credit for the engine in Notes and Credits and will also use it for 2x3, 3x3, 3x4 and 4x4 Sudokus.
Last edited by EDGE_X (Sept. 28, 2021 23:54:59)
- DaCatBlock
-
100+ posts
Sudoku Engine Help
Ah yes. Sudoku.
Although I can’t really help too much, I can certainly point you in the right direction. I recommend looking up Python algorithms, because Python is basically scratch in typing form. I would also suggest Wikipedia articles about how sudoku works and looking at other scratcher’s projects to learn more. If you have some list and logical thinking experience, making it shouldn’t be too difficult
Although I can’t really help too much, I can certainly point you in the right direction. I recommend looking up Python algorithms, because Python is basically scratch in typing form. I would also suggest Wikipedia articles about how sudoku works and looking at other scratcher’s projects to learn more. If you have some list and logical thinking experience, making it shouldn’t be too difficult

- EDGE_X
-
100+ posts
Sudoku Engine Help
Ah yes. Sudoku.
Although I can’t really help too much, I can certainly point you in the right direction. I recommend looking up Python algorithms, because Python is basically scratch in typing form. I would also suggest Wikipedia articles about how sudoku works and looking at other scratcher’s projects to learn more. If you have some list and logical thinking experience, making it shouldn’t be too difficult
Thank you for your concern. I am actually going to use lists to determine what value the already filled cells are going to be and what the possible algorithms can be. I also want to prevent some stuff like if the last two numbers are example 1 and 3 in one column and another one has 1 and 3 as the only missing numbers but the 1 and the 3 are both in same rows, it will be impossible to guess which one is right. Well not impossible I should say but more like a blind 50/50 guess. It's pretty complicated so if you don't understand any of what I just said about a 50/50 chance later on I can show you on what I mean about this. Also I am going to add pencil numbers too that will be using another list, it's complicated but that's why I'm starting with 2x2 (technically 4x4 since there are 16 squares but yeah).
- DaCatBlock
-
100+ posts
Sudoku Engine Help
Sounds like you don’t need any help from meAh yes. Sudoku.
Although I can’t really help too much, I can certainly point you in the right direction. I recommend looking up Python algorithms, because Python is basically scratch in typing form. I would also suggest Wikipedia articles about how sudoku works and looking at other scratcher’s projects to learn more. If you have some list and logical thinking experience, making it shouldn’t be too difficult
Thank you for your concern. I am actually going to use lists to determine what value the already filled cells are going to be and what the possible algorithms can be. I also want to prevent some stuff like if the last two numbers are example 1 and 3 in one column and another one has 1 and 3 as the only missing numbers but the 1 and the 3 are both in same rows, it will be impossible to guess which one is right. Well not impossible I should say but more like a blind 50/50 guess. It's pretty complicated so if you don't understand any of what I just said about a 50/50 chance later on I can show you on what I mean about this. Also I am going to add pencil numbers too that will be using another list, it's complicated but that's why I'm starting with 2x2 (technically 4x4 since there are 16 squares but yeah).

- Scratch-Minion
-
1000+ posts
Sudoku Engine Help
Here are some possible ideas for a 4x4 Sudoku.
ie. 4 rows, 4 columns and 4 2x2 squares must all have one of each number.
Often it is good to start with simpler cases but I am not sure it would help much here.
You would need to place a minimum of 3 different numbers in a 4x4 puzzle for a unique solution.
(If you only place 2 different numbers then the other 2 numbers would be interchangeable giving two or more solutions).
I would use an easier (though less efficient) algorithm to place the numbers.
1) Place 3 different numbers randomly but check as you place each number that it conforms with the rules
1A) You may choose to place a couple more numbers that also obey the rules, especially during testing.
These numbers may / may not include the fourth number not yet placed.
If you place 5 numbers on a 4x4 grid (including the 3 different starting numbers) there will definitely be at least one duplicate
2) Now test all combinations of numbers for solutions!
Do this by trying all numbers for each cell, then the next cell ….
If any number is invalid by the rules, then you don't need to test the rest of the cells for that combination.
This cuts down the number of tests hugely.
eg. if row 1 is 4,2,*,* then you don't need to do any more tests on row 1 for values 2 or 4 in the * positions.
Computers are fast! The tests won't take long in a “run without refresh” custom block.
While doing this, count the valid solutions.
If there is more than 1 valid solution, add another starting number to the start grid and try again.
Extra Note: You can look at my KenKen project for ideas: https://scratch.mit.edu/projects/394394842
ie. 4 rows, 4 columns and 4 2x2 squares must all have one of each number.
Often it is good to start with simpler cases but I am not sure it would help much here.
You would need to place a minimum of 3 different numbers in a 4x4 puzzle for a unique solution.
(If you only place 2 different numbers then the other 2 numbers would be interchangeable giving two or more solutions).
I would use an easier (though less efficient) algorithm to place the numbers.
1) Place 3 different numbers randomly but check as you place each number that it conforms with the rules
1A) You may choose to place a couple more numbers that also obey the rules, especially during testing.
These numbers may / may not include the fourth number not yet placed.
If you place 5 numbers on a 4x4 grid (including the 3 different starting numbers) there will definitely be at least one duplicate
2) Now test all combinations of numbers for solutions!
Do this by trying all numbers for each cell, then the next cell ….
If any number is invalid by the rules, then you don't need to test the rest of the cells for that combination.
This cuts down the number of tests hugely.
eg. if row 1 is 4,2,*,* then you don't need to do any more tests on row 1 for values 2 or 4 in the * positions.
Computers are fast! The tests won't take long in a “run without refresh” custom block.
While doing this, count the valid solutions.
If there is more than 1 valid solution, add another starting number to the start grid and try again.
Extra Note: You can look at my KenKen project for ideas: https://scratch.mit.edu/projects/394394842
- Discussion Forums
- » Help with Scripts
-
» Sudoku Engine Help