Get Help

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- Sudoku: Creating and/or Solving

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

10-08-2012
02:40 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

10-08-2012
02:40 PM

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

10-08-2012
08:05 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

10-08-2012
08:24 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

10-08-2012
08:24 PM

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.

10-10-2012
03:50 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

10-10-2012
03:50 AM

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

10-10-2012
01:09 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

10-10-2012
01:09 PM

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.

10-21-2012
02:57 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

10-21-2012
02:57 PM

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?

11-26-2013
02:49 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

11-26-2013
02:49 PM

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