Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'rejected': 0.04; 'url:py': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'output': 0.10; 'clear.': 0.16; 'evaluates': 0.16; 'iterator,': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:t-dialin.net': 0.16; 'url:nabble': 0.16; 'url:old': 0.16; 'wrote:': 0.16; "doesn't": 0.22; 'thus': 0.23; 'testing': 0.24; 'code': 0.25; 'creating': 0.25; "i'm": 0.27; 'code,': 0.28; 'loop': 0.28; 'correct': 0.28; 'order.': 0.29; 'sorry,': 0.29; 'from:addr:web.de': 0.30; 'outer': 0.30; 'ran': 0.30; 'produced': 0.31; 'cases': 0.32; 'expression': 0.32; 'too': 0.33; 'to:addr:python-list': 0.33; 'header:X -Complaints-To:1': 0.35; 'run': 0.37; 'received:org': 0.38; 'should': 0.38; 'subject:: ': 0.39; 'header:Mime-Version:1': 0.39; 'to:addr:python.org': 0.39; 'huge': 0.61; 'your': 0.61; 'total': 0.61; 'dr.': 0.68; 'realizing': 0.84; 'subject:balls': 0.84; 'sum': 0.89 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: recursive algorithm for balls in numbered boxes Date: Sun, 11 Sep 2011 22:13:02 +0200 Organization: None References: <32440187.post@talk.nabble.com> <32443548.post@talk.nabble.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p5084a760.dip.t-dialin.net X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 26 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1315771976 news.xs4all.nl 2537 [2001:888:2000:d::a6]:43714 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:13149 Dr. Phillip M. Feldman wrote: > When I run my code, I get the same 14 configurations that your code > produces; I'm sorry, I ran the buggy code from http://old.nabble.com/file/p32439307/balls_in_numbered_boxes.py without realizing it was not http://old.nabble.com/file/p32440187/balls_in_numbered_boxes.py > the only different that I can see in the output is that the > configurations are produced in a different order. Note that your code is > not creating an iterator, so thus doesn't do what I want. The outer loop is in a generator expression and thus evaluates lazily. > Also, > generating the product set and then testing whether the total number of > balls is correct will potentially consider a huge number of cases that > must be rejected because the sum is wrong; this is too inefficient. Indeed; I should have added a disclaimer to make that clear.