comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adambeneschan@gmail.com>
Subject: Re: OT: A bit  of Sudoku
Date: Thu, 5 Jun 2014 13:40:57 -0700 (PDT)
Date: 2014-06-05T13:40:57-07:00	[thread overview]
Message-ID: <3d4f61d0-8f8f-49e9-a4ce-8fedffc5da10@googlegroups.com> (raw)
In-Reply-To: <tJCAdXM+zMkTFwzN@ada-augusta.demon.co.uk>

On Thursday, June 5, 2014 1:03:10 PM UTC-7, Mike H wrote:

> I chose, perhaps wrongly, that the complete grid of 81 cells is passed 
> down the recursion tree (as IN OUT). At each level, the grid is further 
> completed as the full gamut of deterministic algorithms is exercised 
> before either a lack of further success prompts a further trial and 
> error attempt or a positive failure forces a return of up the tree. 
> Thus, a return of control to a caller is taken as a positive signal of 
> failure. But, currently, there is no equivalent positive indicator of 
> success.

My own experience with problems of this sort has been that passing the entire problem-state to the next level as an IN OUT parameter (or the equivalent, in other languages) makes life more difficult.  The callee needs to be able to make changes to the problem-state in order to try different possibilities; the caller needs the problem-state to stay the same, so that if the callee returns without finding a solution, the caller can try the next thing on the problem-state it was given as an input parameter.  The last time I wrote a Sudoku solver, I therefore made sure the grid I passed to recursive calls was a (modified) copy of the input parameter, not a reference to the same parameter.  For some kinds of problems, this might be unfeasible; but an array of 81 integers is pretty easy to handle.  By the way, the program found answers almost instantaneously, and it used only backtracking--no attempt to try to deal with simple cases the way I would approach it if solving by hand.  So while it might be interesting (and instructive) to try to write a program that will work optimally, in practice it isn't necessary for this particular game.

Good luck.  Backtracking programs aren't easy to write correctly.

                                    -- Adam


  reply	other threads:[~2014-06-05 20:40 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-05 17:49 OT: A bit of Sudoku Mike H
2014-06-05 18:30 ` Adam Beneschan
2014-06-05 19:00   ` J-P. Rosen
2014-06-05 19:18     ` Jeffrey Carter
2014-06-05 19:43       ` J-P. Rosen
2014-06-05 20:05     ` Mike H
2014-06-05 23:12     ` Robert A Duff
2014-06-05 23:39       ` Adam Beneschan
2014-06-06  7:51         ` Dmitry A. Kazakov
2014-06-06  9:21           ` Georg Bauhaus
2014-06-06 13:38             ` Dmitry A. Kazakov
2014-06-06 15:47           ` Adam Beneschan
2014-06-06 17:09             ` Dmitry A. Kazakov
2014-06-07  6:03             ` J-P. Rosen
2014-06-06 14:13         ` Brad Moore
2014-06-13  0:21     ` Shark8
2014-06-13  6:30       ` J-P. Rosen
2014-06-13 10:10       ` Mike H
2014-06-13 12:37         ` Dmitry A. Kazakov
2014-06-13 15:47         ` Shark8
2014-06-05 20:03   ` Mike H
2014-06-05 20:40     ` Adam Beneschan [this message]
2014-06-06  9:10       ` Stefan.Lucks
2014-06-06 10:59         ` Mike H
2014-06-06 16:06         ` Adam Beneschan
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox