Discuss Scratch

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:
  1. No list or hacked blocks can be used (all other blocks are allowed)
  2. All your code must be within the “Solver” sprite
  3. The original template code can't be changed (excluding the “solve sudoku grid” custom block)
If the AMC becomes too tough however, I will be open to revising the restrictions on blocks

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)
  1. The algorithm produces a valid solution for any sudoku grid given
  2. The code is efficient
  3. The code follows DRY (Don't Repeate Yourself) principals (so use loops, create custom blocks, etc.)
  4. The code is well commented (useful comments please, don't state the obvious )
  5. 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:
  1. The grid will always be 9x9
  2. There will always be (at least) 1 solution for each grid given
  3. 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

jokebookservice1 wrote:

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

chooper100 wrote:

jokebookservice1 wrote:

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
Ok then
IcyCoder
Scratcher
1000+ posts

[AMC #5] Sudoku Solver

third!

this looks like a cool challenge!
_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

_nix wrote:

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

jokebookservice1 wrote:

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

chooper100 wrote:

jokebookservice1 wrote:

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
Does this include
while <> {
}
?

Saiid
jokebookservice1
Scratcher
1000+ posts

[AMC #5] Sudoku Solver

Saiid wrote:

chooper100 wrote:

jokebookservice1 wrote:

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
Does this include
while <> {
}
?

Saiid
It doesn't matter since it can be replicated using normal blocks though…
repeat until <not <>>

end
chooper100
Scratcher
500+ posts

[AMC #5] Sudoku Solver

Saiid wrote:

chooper100 wrote:

jokebookservice1 wrote:

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
Does this include
while <> {
}
?

Saiid
I consider a hacked block to be any block / block configuration that it is not possible to create within the online Scratch editor.

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

chooper100 wrote:

Saiid wrote:

chooper100 wrote:

jokebookservice1 wrote:

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
Does this include
while <> {
}
?

Saiid
I consider a hacked block to be any block / block configuration that it is not possible to create within the online Scratch editor.

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
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?

Saiid
Sigton
Scratcher
1000+ posts

[AMC #5] Sudoku Solver

Using Declarative Programming would make this quite interesting…

Sigton
chooper100
Scratcher
500+ posts

[AMC #5] Sudoku Solver

Sigton wrote:

Using Declarative Programming would make this quite interesting…

Sigton
I'm confused how declarative programming could be used here?

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

chooper100 wrote:

Sigton wrote:

Using Declarative Programming would make this quite interesting…

Sigton
I'm confused how declarative programming could be used here?

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
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.

Sigton
Saiid
Scratcher
1000+ posts

[AMC #5] Sudoku Solver

Sigton wrote:

chooper100 wrote:

Sigton wrote:

Using Declarative Programming would make this quite interesting…

Sigton
I'm confused how declarative programming could be used here?

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
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.

Sigton
*wiggles eyebrows* Machine Learning

Saiid
chooper100
Scratcher
500+ posts

[AMC #5] Sudoku Solver

Saiid wrote:

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

chooper100 wrote:

Saiid wrote:

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
Not all

Saiid

Powered by DjangoBB