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


Groups > comp.lang.python > #13146 > unrolled thread

Re: recursive algorithm for balls in numbered boxes

Started by"Dr. Phillip M. Feldman" <Phillip.M.Feldman@gmail.com>
First post2011-09-11 12:41 -0700
Last post2011-09-11 12:41 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: recursive algorithm for balls in numbered boxes "Dr. Phillip M. Feldman" <Phillip.M.Feldman@gmail.com> - 2011-09-11 12:41 -0700

#13146 — Re: recursive algorithm for balls in numbered boxes

From"Dr. Phillip M. Feldman" <Phillip.M.Feldman@gmail.com>
Date2011-09-11 12:41 -0700
SubjectRe: recursive algorithm for balls in numbered boxes
Message-ID<mailman.1004.1315770096.27778.python-list@python.org>
Hello Peter,

When I run my code, I get the same 14 configurations that your code
produces; 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.  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.

Phillip

In [2]: list(balls_in_numbered_boxes(10,[4,3,2,1,2]))
Out[2]:
[(4, 3, 2, 1, 0),
 (4, 3, 2, 0, 1),
 (4, 3, 1, 1, 1),
 (4, 3, 1, 0, 2),
 (4, 3, 0, 1, 2),
 (4, 2, 2, 1, 1),
 (4, 2, 2, 0, 2),
 (4, 2, 1, 1, 2),
 (4, 1, 2, 1, 2),
 (3, 3, 2, 1, 1),
 (3, 3, 2, 0, 2),
 (3, 3, 1, 1, 2),
 (3, 2, 2, 1, 2),
 (2, 3, 2, 1, 2)]
-- 
View this message in context: http://old.nabble.com/recursive-algorithm-for-balls-in-numbered-boxes-tp32440187p32443548.html
Sent from the Python - python-list mailing list archive at Nabble.com.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web