From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.cs.hut.fi!newsfeed2.funet.fi!newsfeeds.funet.fi!goblin2!goblin.stu.neva.ru!cyclone03.ams2.highwinds-media.com!news.highwinds-media.com!voer-me.highwinds-media.com!post02.fr7!fx28.fr7.POSTED!not-for-mail Message-ID: From: Mike H Reply-To: Mike Hopkins Newsgroups: comp.lang.ada Subject: OT: A bit of Sudoku MIME-Version: 1.0 Content-Type: text/plain;charset=utf-8;format=flowed Content-Transfer-Encoding: 8bit User-Agent: Turnpike/6.07-M (<0Ww$+brc77PuI7divS2NqpEDZt>) NNTP-Posting-Host: 83.104.138.185 X-Complaints-To: abuse@demon.net X-Trace: 1401990551 83.104.138.185 (Thu, 05 Jun 2014 17:49:11 UTC) NNTP-Posting-Date: Thu, 05 Jun 2014 17:49:11 UTC Date: Thu, 5 Jun 2014 18:49:01 +0100 X-Received-Body-CRC: 76535480 X-Received-Bytes: 2625 Xref: news.eternal-september.org comp.lang.ada:20144 Date: 2014-06-05T18:49:01+01:00 List-Id: 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)