Sudoku
Eric Parry
joan4eric at gmail.com
Sat Mar 30 18:06:19 EDT 2013
On Saturday, March 30, 2013 8:41:08 AM UTC+10:30, Dave Angel wrote:
> 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
The exit() did not work.
I replaced it with return = 0, and that does work.
Eric.
More information about the Python-list
mailing list