Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #13149

Re: recursive algorithm for balls in numbered boxes

From Peter Otten <__peter__@web.de>
Subject Re: recursive algorithm for balls in numbered boxes
Date 2011-09-11 22:13 +0200
Organization None
References <32440187.post@talk.nabble.com> <j4iamn$ave$1@dough.gmane.org> <32443548.post@talk.nabble.com>
Newsgroups comp.lang.python
Message-ID <mailman.1007.1315771976.27778.python-list@python.org> (permalink)

Show all headers | View raw


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.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: recursive algorithm for balls in numbered boxes Peter Otten <__peter__@web.de> - 2011-09-11 22:13 +0200

csiph-web