cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Sudoku: Creating and/or Solving

HarveyHensley
3-Visitor

Sudoku: Creating and/or Solving

There are very few Sudoku solvers in the Community and the one I saw doesn't work on the harder problems.  The attached file can be used to create problems in a random manner with some control on the level of difficulty.  This control is provided by setting the number of cells with non-zero starting values and a lower bound on the number of cells provided in the 3x3 squares.  If the user wishes, a manual starting matrix can be supplied as a problem instead of using the randomly generated problem.

The program starts with logic loops that I used to solve problems by hand.  When the solution reaches the point where it appears (to me) that the problem becomes a trial and error process, then the program goes into that mode.  The solution provides a printout of the number of logic outer loops and the number of trial and error guesses needed.

I created this worksheet several years ago, so even I can't understand the program now.  Therefore, don't ask for explanation.  It's just presented for your enjoyment.  Part of that enjoyment may be figuring out how the program works.  Once I got this working, I was through with Sudoku.

The program is in Mathcad 15.

6 REPLIES 6

That's the one I tried and it would not solve the problem I submitted, which I think is the manually input problem in my worksheet.  The author says it will only solve problems of medium difficulty.

Great worksheet, tried it with the sudoku below supposedly the hardest in the world.

Solution pops out in 108 loops with only 9 trial/error loops.

Better at it than me...

Regards

     Andy

8 0 0 0 0 0 0 0 0

0 0 3 6 0 0 0 0 0

0 7 0 0 9 0 2 0 0

0 5 0 0 0 7 0 0 0

0 0 0 0 4 5 7 0 0

0 0 0 1 0 0 0 3 0

0 0 1 0 0 0 0 6 8

0 0 8 5 0 0 0 1 0

0 9 0 0 0 0 4 0 0

Thanks for trying it and sending your problem and results.  I played around with the limit on the number of logic loops allowed and found out that cutting off even one logic pass results in an incorrect solution.  This is true also of the original problem that I submitted.

Several years ago there were contests for Sudoku solvers.  The "ideal" was to use only logic, not trial and error.  Thus, my program would not be a contender.  Another contest was for the fewest lines of code.  The winner wrote a one line program in Pascal as I recall.  The line wasn't all that long either, but I couldn't understand it.  Most likely it was all trial and error with recursion. 

As you can see, my program is 14 pages long.  I think that is much longer than my reactor model programs.  I saw a video on this site by by a Villanova professor who said that Mathcad shouldn't be used for progams that have a lot of loops and if-thens.  Why not?  Any other program is going to be just as long, or longer.  Personally, I like the programming structures in Mathcad.

Because of the success with the problem Andy reported, I have tested it against several other difficult problems.  The results were mixed: it solved many but not all.

My conclusion from those few results: it's a good program but probably far from the best.  But for now, I think it is the champion of the PTC Community.  Any challengers?

I am in awe of your Soduku program.  Excellent work, but I won't even try to understand it.

Announcements
Check out the latest
Mathcad Tip
"PTC Mathcad 15 / Prime 1-6 Update."