comp.lang.ada
 help / color / mirror / Atom feed
From: Mike H <postmaster@ada-augusta.demon.co.uk>
Subject: OT: A bit  of Sudoku
Date: Thu, 5 Jun 2014 18:49:01 +0100
Date: 2014-06-05T18:49:01+01:00	[thread overview]
Message-ID: <d9OMQAHN2KkTFw2f@ada-augusta.demon.co.uk> (raw)

Purely for my own amusement I have written a Sudoku puzzle solver. The 
program is written In Ada. However being in my ninth decade I am firmly 
stuck in an Ada95 time-warp. As a general rule, Sudoku puzzles rated as 
'gentle' or 'moderate' can be solved by systematic elimination of 
alternatives. But these relatively simple deterministic methods can be 
expected to fail when confronted by a puzzle rated as 'tough' or a 
'diabolical'. When this happens in my program, trial and error is 
invoked. It is rare that more than four or five trial and error passes 
are required.

The enclosing subprogram is called recursively by the trial and error 
process. Each recursive call adds a pair of nodes onto an implicit but 
invisible binary tree (the run-time call stack). What I was hoping was 
that on detected that the solution has been found, it would be possible 
to return to, and exit from, the main program by simply exiting each 
recursive call in turn in order climb back up the recursion ladder. 
However, each step of that climb is a re-entry into the caller where 
there may be remaining unfinished business. The solution having been 
found, that unfinished business is now known to be no more than garbage. 
Nevertheless an elegant solution might be expected to clear garbage 
before that caller re-enters its own caller.

The only solution that I can see is to jump straight out of the tree. 
But that seems to lack elegance. The jump is made by raising an 
exception which has been declared in, and is handled by, the enclosing 
subprogram. The exception is 'silent' because the handler contains a 
null statement.

I fear that perhaps I am missing something but have no idea what.
-- 
Cotswold Mike
'Homo sum, humani nihil a me alienum puto' =
'I am human, (so) I (should) judge nothing of humanity to be strange.'
Publius Terentius (195/185–159 BC)

             reply	other threads:[~2014-06-05 17:49 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-05 17:49 Mike H [this message]
2014-06-05 18:30 ` OT: A bit of Sudoku 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
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