Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!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.115 X-Spam-Level: * X-Spam-Evidence: '*H*': 0.77; '*S*': 0.00; 'calculating': 0.09; 'explanation': 0.09; 'friday,': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; 'bug': 0.12; 'helps!': 0.16; 'terminate.': 0.16; 'wrote:': 0.18; 'code.': 0.18; '>>>': 0.22; 'example': 0.22; 'otherwise,': 0.22; 'cc:addr:python.org': 0.22; 'header:User-Agent:1': 0.23; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'header:In-Reply- To:1': 0.27; 'function': 0.29; 'rest': 0.29; 'chris': 0.29; 'am,': 0.29; '(like': 0.30; 'closer': 0.31; 'comparison': 0.31; 'depth': 0.31; 'douglas': 0.31; 'critical': 0.32; 'quite': 0.32; 'running': 0.33; 'fri,': 0.33; 'case,': 0.35; 'no,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'explains': 0.36; 'found.': 0.36; 'list': 0.37; 'list.': 0.37; 'sometimes': 0.38; 'thank': 0.38; 'rather': 0.38; 'itself': 0.39; 'how': 0.40; 'eventually': 0.60; 'is.': 0.60; 'simple,': 0.60; 'hope': 0.61; 'march': 0.61; 'numbers': 0.61; 'further': 0.61; 'first': 0.61; 'maximum': 0.63; 'sum': 0.64; 'mar': 0.68; 'answer.': 0.68; 'results': 0.69; 'receive': 0.70; 'anyone.': 0.74; 'obvious': 0.74; 'condition.': 0.84; 'obvious.': 0.84; 'standing': 0.84; 'exceeded': 0.97; '2013': 0.98 X-Received: by 10.50.186.202 with SMTP id fm10mr45529igc.10.1364593651661; Fri, 29 Mar 2013 14:47:31 -0700 (PDT) Newsgroups: comp.lang.python Date: Fri, 29 Mar 2013 14:47:31 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=122.151.66.173; posting-account=JzVE4wkAAADCSo8EXJLK0dGqAu47aMvq References: <9dla2a-kql.ln1@satorlaser.homedns.org> <5ce10a13-be58-4548-85df-e1d865d3304e@googlegroups.com> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 122.151.66.173 MIME-Version: 1.0 Subject: Re: Sudoku From: Eric Parry To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 72 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1364594426 news.xs4all.nl 6963 [2001:888:2000:d::a6]:47925 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:42284 On Friday, March 29, 2013 9:15:36 AM UTC+10:30, Chris Angelico wrote: > On Fri, Mar 29, 2013 at 9:11 AM, Eric Parry wrote: > > > Thank you for that explanation. > > > No, I do not understand recursion. It is missing from my Python manual. I would be pleased to receive further explanation from anyone. > > > > If you already know what recursion is, just remember the answer. > > Otherwise, find someone who is standing closer to Douglas Hofstadter > > than you are; then ask him or her what recursion is. > > > > :) > > > > Recursion is a form of self-referential code. Take this simple, and > > rather silly, means of calculating the sum of numbers in a list (like > > the sum() function): > > > > # The sum of numbers in an empty list is 0. > > # Otherwise it is the first number plus the sum of the rest of the list. > > def list_sum(lst): > > if not lst: return 0 > > return lst[0] + list_sum(lst[1:]) > > > > >>> list_sum([1,2,3,4,5,6]) > > 21 > > > > Note how the function calls itself - but not always. That's critical > > to recursion - a termination condition. In this case, it's quite > > obvious that the list will eventually have nothing left in it, so the > > function will terminate. Sometimes it's less obvious. Sometimes a bug > > results in infinite recursion... and: > > > > RuntimeError: maximum recursion depth exceeded in comparison > > > > Hope that helps! > > > > ChrisA Thank you for that example Chris. That explains why the program keeps running after a solution is found. Eric