comp.lang.ada
 help / color / mirror / Atom feed
From: Stefan.Lucks@uni-weimar.de
Subject: Re: OT: A bit  of Sudoku
Date: Fri, 6 Jun 2014 11:10:43 +0200
Date: 2014-06-06T11:10:43+02:00	[thread overview]
Message-ID: <alpine.DEB.2.10.1406061056170.1469@debian> (raw)
In-Reply-To: <3d4f61d0-8f8f-49e9-a4ce-8fedffc5da10@googlegroups.com>

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1783 bytes --]

On Thu, 5 Jun 2014, Adam Beneschan wrote:

> 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.

It really depends on the problem you are trying to solve.

> 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.

Right. So the callee *must* undo the change(s) it made, before returning 
without a solution. If undoing is that trivial, then an in-out parameter 
(or "global" variable declared in some outer scope) for the state is 
reasonable. It may even be useful to transfer a solution found back to the 
callee (just don't undo the changes you made ...).

As I understand for the Sudoku case, the entire change is to assign a 
digit to an empty cell, and undoing means to turn the cell's state back to 
empty. If I am right, undoing changes is very easy, indeed!

> The last time I wrote a Sudoku solver,

Well, I have never written a Sudoku solver, but I did apply the 
above approach to other backtracking problems, see, e.g., 
<http://rosettacode.org/wiki/Knight%27s_tour#Ada>.

BTW, a Sudoku-solver for Ada is still missing at Rosetta Code 
<http://rosettacode.org/wiki/Sudoku>.


So long

Stefan

------  I  love  the  taste  of  Cryptanalysis  in  the morning!  ------
     <http://www.uni-weimar.de/cms/medien/mediensicherheit/home.html>
--Stefan.Lucks (at) uni-weimar.de, Bauhaus-Universität Weimar, Germany--

  reply	other threads:[~2014-06-06  9:10 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
2014-06-06  9:10       ` Stefan.Lucks [this message]
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