ANN: Sudoku Assistant

Alex Tweedly alex at tweedly.net
Sat Jul 30 16:40:03 EDT 2005


Dan Shafer wrote:

> Oh, thanks a LOT, Alex! Now I'll waste the entire freaking weekend  
> doing Sudoku. I am already hooked! I never saw this kind of puzzle  
> before (and after reading the article in Wikipedia, I know why;  
> they're pretty new in terms of wide popularity) but it so fits my  
> obsession with numeric patterns that I'm afraid I may just have found  
> the thing that will ultimately destroy all that remains of my  
> productivity.

I only discovered them in May - they were mentioned on slashdot, and a 
couple of days later I went on vacation - and found myself with laptop 
but without Internet connectivity. In the airport on the way, I bought a 
newspaper, which had a couple of puzzles in it.  The program was the 
result ....  but I found the idea of writing a program to do it more 
appealing than doing the puzzles myself.

> I noticed a couple of things as I began working with your program.
>
> First, I noticed that when I choose one of the puzzles with some  
> givens in it, those givens are not eliminated from the display list  
> of possibilities for other squares in the region. As I understand the  
> rules of Sudoku -- and my knowledge base is less than two hours old  
> at this point -- that would be quite helpful and would be expected, no?

Yes, it would be *too* helpful. In fact, if I did that immediately, you 
would only see completed puzzles for number 1,2 and 3. Number 4 is a lot 
harder than the others - they can be "solved" simply by diligently 
applying the rule of eliminating row,col,square for those squares which 
have only a single value left. Puzzle 4 requires a big step up to 
eliminating values due to common pairs. (I'll say no more in case that 
would be a "spoiler" for anyone).

So you get to do a little bit of work - you can click on a square 
containing a single value, and it will eliminate that value from the 
rest of its in the row, column and 3x3 square.  Or, if you're impatient, 
you can click on the "Auto" button and it will do that for you, to each 
button in turn.

> Second, when I loaded puzzle #1, at some point in solving it, the  
> square I'll call square 7 (lower left) in the lower-right region  
> suddenly became blank and responded to clicks only by highlighting.  
> It was no longer possible to put a value into that cell. That cell  
> was NOT a given when the puzzle started.

I've seen that once, but not been able to reproduce it. I am 80% sure it 
was a follow-on from filling-in a wrong answer (which causes a "?" to 
appear somewhere), and then Undo-ing my way back past that point. I made 
a couple of fixes since I saw it, nothing that I could tie in to that 
symptom - but natural optimism made me hope I had fixed it as a 
side-effect.

I'll try again to make it happen (and code-review the Undo after error 
cases).

>
> Third, when played in the IDE, your program brings up the message box  
> all the time, which is just slightly annoying. I'm guessing that if I  
> compile it into a standalone that problem would go away.

Hmmm - I must have left in a debug statement somewhere. My fault - I 
usually use a "log" function, but originally this was going to be 
"throw-away" code that I wrote for amusement during my vacation, and 
didn't intend to do anything more with. I'll look for that too ...

> Fourth -- and perhaps related to my second point above -- the number  
> of solution values in the right column dropped to 0 at some point and  
> stayed there. I took that to mean I had an error somewhere in the  
> partial solution but after careful inspection, it seemed OK. But my  
> scan may have overlooked the problem cited as the second point above,  
> so that may be moot and expected behavior.

Yes, it does mean that there is a wrong answer. You didn't by any chance 
read the "Help" info ?  :-)
The last sentence says:

> Also, the number of remaining possible combinations shown on the right 
> will be 0, so it will be fairly obvious. You can then Undo and try 
> another value, or try a different square.

When you put in an incorrect value for a square, it will eliminate that 
number from rest of the the row, col and 3x3 square. If this results in 
there being no possible values remaining, that square gets a "?" - and 
the number of possible combinations goes to 0.  So if you notice it's at 
0, Undo until you get back above the highest "0" line, then Redo once 
and check the row,col and square corresponding to that last change for 
any "?"s. Note this does NOT mean that your last entered value is wrong; 
it could in fact be that this one is correct and there was an earlier 
wrong value, which means that this correct step eliminates the last 
possible value from some square.


> It occurred to me it would be way cool if I could take a puzzle from  
> a magazine, enter the givens in your assistant and save it. I know  
> you have a mechanism for loading a text file with a known format that  
> would also accomplish that but unless you have plans to implement  
> that, I may take a crack at it.
>
That would be very easy - I'll do that at the same time as I fix the 
spelling mistakes in the Help info and re-upload to RevOnline in an hour 
or so .... 


-- 
Alex Tweedly       http://www.tweedly.net



-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.338 / Virus Database: 267.9.6/59 - Release Date: 27/07/2005




More information about the use-livecode mailing list