Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » [AMC #5] Sudoku Solver
- chooper100
-
Scratcher
500+ posts
[AMC #5] Sudoku Solver
Hello,
I am pleased to announce the 5th challenge in the AMC series:
Build an algorithm to solve any 9x9 sudoku puzzle
Click here if you don't know what sudoku is
However, this is an AMC, so there are some restrictions:
Note: These restrictions were chosen as I am aware that a large number of standard sudoku solver algorithms already exist
Criteria used when judging: (in order of importance)
How I will test projects:
Projects will be tested using the default grids provided in the project itself
I will also check it works with a couple of unseen sudoku grids to prevent cheating
Assumptions you are allowed to make:
To save time, you are allowed to make the following assumptions about the sudoku grids provided:
Opportunities to impress:
Some of the puzzles given will require a certain element of brute force checking to solve
However, due to the nature of sudoku puzzles, there is a good opportunity to nail out a large number of possibilities through logic
Any projects displaying this will score highly
Template project: (remix this when entering)
https://scratch.mit.edu/projects/135801788/
Deadline:
I will set the deadline for 2 weeks tomorrow: 26th December
This deadline is flexible however
Studio for entries:
https://scratch.mit.edu/studios/3637095/
Good luck to everyone!
I am pleased to announce the 5th challenge in the AMC series:
Build an algorithm to solve any 9x9 sudoku puzzle
Click here if you don't know what sudoku is
However, this is an AMC, so there are some restrictions:
- No list or hacked blocks can be used (all other blocks are allowed)
- All your code must be within the “Solver” sprite
- The original template code can't be changed (excluding the “solve sudoku grid” custom block)
Note: These restrictions were chosen as I am aware that a large number of standard sudoku solver algorithms already exist
Criteria used when judging: (in order of importance)
- The algorithm produces a valid solution for any sudoku grid given
- The code is efficient
- The code follows DRY (Don't Repeate Yourself) principals (so use loops, create custom blocks, etc.)
- The code is well commented (useful comments please, don't state the obvious
) - The code is well layed out (and generally follows good practices - eg. meaningful variable names)
How I will test projects:
Projects will be tested using the default grids provided in the project itself
I will also check it works with a couple of unseen sudoku grids to prevent cheating
Assumptions you are allowed to make:
To save time, you are allowed to make the following assumptions about the sudoku grids provided:
- The grid will always be 9x9
- There will always be (at least) 1 solution for each grid given
- If a puzzle does have multiple valid solutions, your algorithm does not need to always produce the same solution (albeit I can't see why it would do that)
Opportunities to impress:
Some of the puzzles given will require a certain element of brute force checking to solve
However, due to the nature of sudoku puzzles, there is a good opportunity to nail out a large number of possibilities through logic
Any projects displaying this will score highly
Template project: (remix this when entering)
https://scratch.mit.edu/projects/135801788/
Deadline:
I will set the deadline for 2 weeks tomorrow: 26th December
This deadline is flexible however
Studio for entries:
https://scratch.mit.edu/studios/3637095/
Good luck to everyone!
Last edited by chooper100 (Dec. 11, 2016 18:11:00)
- jokebookservice1
-
Scratcher
1000+ posts
[AMC #5] Sudoku Solver
I cannot wait! Are hacked blocks allowed?
- chooper100
-
Scratcher
500+ posts
[AMC #5] Sudoku Solver
Are hacked blocks allowed?
My initial thought is to not allow hacked blocks, but again, if the challenge becomes too difficult I will be open to changing this decision
- jokebookservice1
-
Scratcher
1000+ posts
[AMC #5] Sudoku Solver
Ok thenAre hacked blocks allowed?
My initial thought is to not allow hacked blocks, but again, if the challenge becomes too difficult I will be open to changing this decision

- _nix
-
Scratcher
1000+ posts
[AMC #5] Sudoku Solver
I could use the “algorithm” I always use for solving sudoku puzzles, but I haven't done enough puzzles to be sure it always works. I imagine it wouldn't work on puzzles where there aren't very many default tiles..
- jokebookservice1
-
Scratcher
1000+ posts
[AMC #5] Sudoku Solver
I could use the “algorithm” I always use for solving sudoku puzzles, but I haven't done enough puzzles to be sure it always works. I imagine it wouldn't work on puzzles where there aren't very many default tiles..You could do your algorithm and upon failure use trial and error and recursively try again. Though that would be inefficient.
@chooper100 are we allowed to use a pre-existing algorithm?
- IcyCoder
-
Scratcher
1000+ posts
[AMC #5] Sudoku Solver
OK so my algorithm is really simple (very slow speed wise) but it works and it is easy to comment what is going on. The no list restriction is surprisingly not a problem for me… which is great.
- chooper100
-
Scratcher
500+ posts
[AMC #5] Sudoku Solver
are we allowed to use a pre-existing algorithm?
Yes, although the restrictions on lists means that you will probably have to change some parts of it
Also, you will still need to show an understanding of how the code actually works (by commenting it)
- Saiid
-
Scratcher
1000+ posts
[AMC #5] Sudoku Solver
Does this includeAre hacked blocks allowed?
My initial thought is to not allow hacked blocks, but again, if the challenge becomes too difficult I will be open to changing this decision
while <> {
}?Saiid
- jokebookservice1
-
Scratcher
1000+ posts
[AMC #5] Sudoku Solver
It doesn't matter since it can be replicated using normal blocks though…Does this includeAre hacked blocks allowed?
My initial thought is to not allow hacked blocks, but again, if the challenge becomes too difficult I will be open to changing this decisionwhile <> {?
}
Saiid
repeat until <not <>>
end
- chooper100
-
Scratcher
500+ posts
[AMC #5] Sudoku Solver
I consider a hacked block to be any block / block configuration that it is not possible to create within the online Scratch editor.Does this includeAre hacked blocks allowed?
My initial thought is to not allow hacked blocks, but again, if the challenge becomes too difficult I will be open to changing this decisionwhile <> {?
}
Saiid
Therefore, I would not allow that block as it requires mods for it to be made available through Scratch
Btw, why would you even need that? It is exactly the same as
repeat until <not (some condition)>
...
end
EDIT:
Partially Ninja'd by jokebookservice1

Last edited by chooper100 (Dec. 11, 2016 19:25:35)
- Saiid
-
Scratcher
1000+ posts
[AMC #5] Sudoku Solver
Not really, I've got it in my backpack, but anyway, I just prefer to use it over that workaround, I find it easier. And since it does in fact have that workaround, can I use it?I consider a hacked block to be any block / block configuration that it is not possible to create within the online Scratch editor.Does this includeAre hacked blocks allowed?
My initial thought is to not allow hacked blocks, but again, if the challenge becomes too difficult I will be open to changing this decisionwhile <> {?
}
Saiid
Therefore, I would not allow that block as it requires mods for it to be made available through Scratch
Btw, why would you even need that? It is exactly the same asrepeat until <not (some condition)>
...
end
EDIT:
Partially Ninja'd by jokebookservice1
Saiid
- Sigton
-
Scratcher
1000+ posts
[AMC #5] Sudoku Solver
Using Declarative Programming would make this quite interesting…
Sigton
Sigton
- chooper100
-
Scratcher
500+ posts
[AMC #5] Sudoku Solver
Using Declarative Programming would make this quite interesting…I'm confused how declarative programming could be used here?
Sigton
The only example of declarative programming here I can think of is what the demo code is doing - it gets the “solve sudoku grid” block to solve the puzzle, but it doesn't care exactly how it goes about solving it
- IcyCoder
-
Scratcher
1000+ posts
[AMC #5] Sudoku Solver
Guys I am officially Bald… Thanks so much chooper (sarcazm)! 

- Sigton
-
Scratcher
1000+ posts
[AMC #5] Sudoku Solver
I suppose it isn't really a solving algorithm as such, but it really interests me how you can describe the problem to a program so it can solve it, rather than giving it instructions on how it's solved.Using Declarative Programming would make this quite interesting…I'm confused how declarative programming could be used here?
Sigton
The only example of declarative programming here I can think of is what the demo code is doing - it gets the “solve sudoku grid” block to solve the puzzle, but it doesn't care exactly how it goes about solving it
Sigton
- Saiid
-
Scratcher
1000+ posts
[AMC #5] Sudoku Solver
*wiggles eyebrows* Machine LearningI suppose it isn't really a solving algorithm as such, but it really interests me how you can describe the problem to a program so it can solve it, rather than giving it instructions on how it's solved.Using Declarative Programming would make this quite interesting…I'm confused how declarative programming could be used here?
Sigton
The only example of declarative programming here I can think of is what the demo code is doing - it gets the “solve sudoku grid” block to solve the puzzle, but it doesn't care exactly how it goes about solving it
Sigton
Saiid
- chooper100
-
Scratcher
500+ posts
[AMC #5] Sudoku Solver
Not really, I've got it in my backpack, but anyway, I just prefer to use it over that workaround, I find it easier. And since it does in fact have that workaround, can I use it?
All hacked blocks have workarounds (albeit this one is much simpler than others).
Therefore I'll stick with my current position and say that it isn't allowed
- Saiid
-
Scratcher
1000+ posts
[AMC #5] Sudoku Solver
Not allNot really, I've got it in my backpack, but anyway, I just prefer to use it over that workaround, I find it easier. And since it does in fact have that workaround, can I use it?
All hacked blocks have workarounds (albeit this one is much simpler than others).
Therefore I'll stick with my current position and say that it isn't allowed

Saiid
- Discussion Forums
- » Advanced Topics
-
» [AMC #5] Sudoku Solver