Sudoku

Dave Angel davea at davea.name
Thu Mar 28 05:36:02 CET 2013


On 03/27/2013 11:00 PM, Eric Parry wrote:
> On Wednesday, March 27, 2013 6:28:01 PM UTC+10:30, Ulrich Eckhardt wrote:
>>
      <SNIP the double-spaced garbage that GoogleGroups put in - see 
http://wiki.python.org/moin/GoogleGroupsPython >
>
> Thank you for your explanation.
> I noticed that in this particular puzzle when it ran out of candidates in a particular cycle, it then changed the last entry to the next one in line in the previous cycle. But I cannot find any code to do this.
> I was hoping to understand the logic so that I could re-write it in VBA for excel which would enable any puzzle to be entered directly.
> Your comments are a big help especially the double negative aspect.
>

Are you familiar with recursion?  Notice the last line in the function 
r() calls the function r() inside a for loop.

So when r() returns, you're back inside the next level up of the 
function, and doing a "backtrack."

When the function succeeds, it will be many levels of recursion deep. 
For example, if the original pattern had 30 nonzero items in it, or 51 
zeroes, you'll be 51 levels of recursion when you discover a solution.

If you don't already understand recursion at all, then say so, and one 
or more of us will try to explain it in more depth.

-- 
DaveA



More information about the Python-list mailing list