Sudoku

Dave Angel davea at davea.name
Fri Mar 29 23:11:08 CET 2013


On 03/29/2013 05:47 PM, Eric Parry wrote:
>
>>   <SNIP>
>>
> That explains why the program keeps running after a solution is found.

A recursive function can be designed to find all solutions, in which 
case it would (as you say) keep running.

The function you posted in the first place uses exit() to avoid keeping 
running.  It stops as soon as a solution is found.

Sometimes a problem cannot be solved in the number of stack entries 
supplied by Python.  So even though such a function will terminate, it 
may crash first if the problem is too big.  Example, the factorial 
problem I described earlier, if you pass it 2000 as a parameter.  If 
this is a problem, one can tell the Python to give you more stack entries.

Given a 9x9 matrix, and at least some of them filled in, the maximum 
depth your code can use is less than 81.  So it won't get a stack 
overflow in any implementation of Python I've seen.  Perhaps in an 8051.

Sometimes a bug in such a function will cause it to run indefinitely, 
and/or to overflow the stack.  I don't see such a bug in this function.


-- 
DaveA



More information about the Python-list mailing list