Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.064 X-Spam-Evidence: '*H*': 0.87; '*S*': 0.00; 'c++,': 0.07; 'column': 0.07; 'squares': 0.07; 'solution,': 0.09; 'mostly': 0.14; 'clear.': 0.16; 'docstring': 0.16; 'entirely.': 0.16; 'left,': 0.16; 'likewise': 0.16; 'program?': 0.16; 'python-based': 0.16; 'rules.': 0.16; 'solver': 0.16; 'somehow.': 0.16; 'turn,': 0.16; 'uniquely': 0.16; 'unwarranted': 0.16; 'url:ics': 0.16; 'url:py': 0.16; 'appropriate': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'solution.': 0.20; 'thanks.': 0.20; 'written': 0.21; '>>>': 0.22; 'code,': 0.22; 'example': 0.22; 'rules': 0.22; 'saying': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'apply.': 0.24; 'logical': 0.24; 'typical': 0.24; 'decide': 0.24; "haven't": 0.24; 'question': 0.24; 'source': 0.25; 'holds': 0.26; 'url:edu': 0.26; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'point': 0.28; 'chris': 0.29; 'am,': 0.29; 'statement': 0.30; "i'm": 0.30; 'cells': 0.31; 'purely': 0.31; 'probably': 0.32; 'another': 0.32; 'maybe': 0.34; "i'd": 0.34; 'could': 0.34; 'something': 0.35; 'objects': 0.35; 'but': 0.35; 'there': 0.35; 'fun,': 0.36; 'sequence': 0.36; 'possible': 0.36; 'should': 0.36; 'error.': 0.37; 'two': 0.37; 'solving': 0.38; 'somebody': 0.38; 'to:addr :python-list': 0.38; 'fact': 0.38; 'pm,': 0.38; 'track': 0.38; "couldn't": 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'enough': 0.39; 'how': 0.40; 'manually': 0.60; 'solve': 0.60; 'ago,': 0.61; 'matter': 0.61; "you're": 0.61; 'making': 0.63; 'reach': 0.63; 'notified': 0.63; 'kind': 0.63; 'skip:n 10': 0.64; 'decided': 0.64; 'telling': 0.64; 'different': 0.65; 'taking': 0.65; 'kept': 0.65; 'charset:windows-1252': 0.65; 'here': 0.66; 'between': 0.67; 'determine': 0.67; 'mar': 0.68; '26,': 0.68; '>from': 0.68; 'received:74.208': 0.68; 'wish': 0.70; 'trial': 0.83; '2015': 0.84; 'blowing': 0.84; 'books.': 0.84; 'bored': 0.84; 'messed': 0.84; 'received:74.208.4.194': 0.84; 'seldom': 0.84; 'water.': 0.84; 'smoke': 0.91 Date: Thu, 26 Mar 2015 10:14:33 -0400 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Sudoku solver References: <87r3sdnw5t.fsf@elektro.pacujo.net> <87fv8sndw1.fsf@elektro.pacujo.net> In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:xqb0ZDRYdJcyc+ecH761nG2jp6k+tGbRHb48+plKce2fUlAjfvp /tiEifTWUcSZXXObi5LN5BVtGbRJb6YExC6pTvu3KldO5Y1rwtv1QAiCbQYgNpKPY6DgNWl jCVGRpnMlD1dW+ELcYA1hE+CAgfqIM28TnKDwgtKNHeX7jn9mibq9Cs6eF8Y5PKci2ZRzXl 91EDGetoaA4f0U0N8HbEg== X-UI-Out-Filterresults: notjunk:1; X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.19 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 67 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1427379292 news.xs4all.nl 2844 [2001:888:2000:d::a6]:47112 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:88055 On 03/26/2015 08:37 AM, Chris Angelico wrote: > On Thu, Mar 26, 2015 at 11:26 PM, Marko Rauhamaa wrote: >> "Frank Millman" : >> >>> Here is another python-based sudoku solver - >>> >>> http://www.ics.uci.edu/~eppstein/PADS/Sudoku.py >>> >>> >From its docstring - >>> >>> "A proper Sudoku puzzle must have a unique solution, and it should be >>> possible to reach that solution by a sequence of logical deductions >>> without trial and error. >> >> I don't think that statement holds water. Trial-and-error is at the >> basis of deduction (reductio ad absurdum). The human solver employs it >> in their head. The question is, what is the difference between >> pen-and-paper and in-your-head for a computer program? > > Nothing. And solving a Sudoku puzzle - or any other puzzle - should > require no guessing. It should be possible to solve purely by logic. > Same goes for every other kind of puzzle out there; it's highly > unsatisfying to play Minesweeper and get to the end with a block of > four squares in a corner, two mines left, and no way of knowing which > diagonal has the mines and which is clear. > > No trial-and-error, thanks. I think you're making an unwarranted assumption here. Your Minesweeper example has two solutions, so there's no way of telling which is the "correct" one. But I'd claim that there are puzzles which have exactly one solution, but which need trial and error at some point to find that solution. I'm not sure how to prove it, since somebody could claim that I just haven't tried all the non-trial-and-error rules. I did write a Sudoku-solver many years ago, in C++, and it solved the typical Sudoku I fed it in about 2ms. But it was deliberately written to apply only rules that humans could readily apply. No backtracking. I did not at that time have any electronic source for puzzles, and I got bored with manually entering them in from puzzle books. So I never actually encountered a puzzle it couldn't solve. I mostly used it to determine that a puzzle I couldn't manually solve was in fact uniquely solvable, and that I'd just messed up somehow. I wish I still had that source code, as it probably sounds like I'm blowing smoke here. The general approach I used was to make objects of each of the cells, which tracked its neighbors to decide whether its value was determined. And when it was determined, it notified its other neighbors. In turn, if that decided a value for any of the neighbors, that cell notified its neighbors. Likewise each row or column or box kept track of its state and notified the appropriate cells whenever something interesting was discovered. Then the outer loop just tickled each cell in turn, and the solution rippled out. Maybe I'm misinterpreting your phrase "No trial and error, thanks". Perhaps you're saying that puzzles that require trial and error are no fun to solve for humans. And that's a different matter entirely. I do the daily KenKen puzzles in my local paper, and they're just hard enough to be fun, seldom taking longer than I'm willing to take in the mornings. -- DaveA