
Title:
Sudoku Solver  Software Testing

Description:

Like I said in the problem, I'm going to show you a fairly naive bruteforce solution to this

that is definitely vulnerable to some things.

First of, we start up with the check Sudoku function from the first problem.

Exact same function as the base for solving this real board.

After that solve Sudoku is actually fairly short if not exactly pretty or copy in sys here

and copy is the only needed here, sys is used down below

for something that is entirely for testing purposes.

First we check the grid then check Sudoku

and if check Sudoku returns none or false, we returned the result.

You could also assert here, I wanted to be able to continue on

for testing purposes so I just return the result instead of asserting that,

although asserting would definitely be a good idea here as well

and we used deep copy to copy this over

and not going to get into what exactly the copy package and deep copy is.

Surprise to say that we made a copy of the initial input into another.

Now, we check through the grid for zero elements

and we change them to each of 1 through 9 and then recursively call solve Sudoku on the results.

This is a very very slow bruteforce process but its also fairly easy to call that as well.

Each element in the grid, which I put zero and then for all and in the range 1 through 10

so all elements 1 through 9 then we set that grid position to that number

and then we call solve Sudoku again.

If this new grid isn't false, then we return it.

Otherwise, we backtrack and that it's it. It's all there is too bad. It's really pretty simple.

There are a lot of ways you could really really mess with this if you wanted it to

take a very very long time for instance and right here break it into forms.

Just to check real quick, let's check that my solution actually works.

and this is for all of the inputs that we gave as example test cases.

You can see that it does verify that the first two,

the L form and the invalid ones didn't work and then for the valid one and easy,

we didn't do ALG simply because it would take this out

on a little bit longer to do that and I didn't want to wait

so that it shows that the valid and already solved board is the exactly the same

and the easy board is filled out with a valid Sudoku board solution.

I hope you enjoyed that and I hope you looking at everyone else's code

and seeing how everyone thought about the problem and how you might think

about testing the problem itself.

I hope you had a lot of fun with that. See you in the next unit.