Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #13187
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <bounces@nabble.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.025 |
| X-Spam-Evidence | '*H*': 0.95; '*S*': 0.00; 'python': 0.08; '[0,': 0.09; 'context:': 0.09; 'recipe': 0.09; '[2,': 0.16; 'message- id:@talk.nabble.com': 0.16; 'nabble.com.': 0.16; 'received:192.168.236': 0.16; 'received:192.168.236.156': 0.16; 'received:216.139': 0.16; 'received:216.139.236': 0.16; 'received:isper.nabble.com': 0.16; 'received:nabble.com': 0.16; 'url:nabble': 0.16; 'url:old': 0.16; 'thanks!': 0.16; 'wrote:': 0.16; 'seems': 0.20; 'suggest': 0.20; 'raymond': 0.21; 'maybe': 0.21; 'header:In-Reply-To:1': 0.22; 'archive': 0.23; '(without': 0.23; 'assigning': 0.23; 'discussed': 0.28; 'handled': 0.28; 'url:mailman': 0.28; 'yields': 0.30; "skip:' 10": 0.30; 'list': 0.32; 'assigned': 0.32; 'to:addr:python-list': 0.33; 'url:listinfo': 0.33; 'charset:us-ascii': 0.36; 'url:python': 0.36; 'question': 0.36; 'useful': 0.36; 'using': 0.37; 'page': 0.37; 'something': 0.37; 'url:org': 0.38; 'subject:: ': 0.39; 'received:192': 0.39; 'getting': 0.39; 'represent': 0.39; 'enough': 0.39; 'to:addr:python.org': 0.39; 'case': 0.39; 'mailing': 0.39; "i'd": 0.40; 'where': 0.40; 'your': 0.61; 'opened': 0.64; 'limit': 0.66; 'view': 0.67; 'probability': 0.67; 'william': 0.68; '"an': 0.84; 'boxes,': 0.84; 'itertools,': 0.84; 'placements': 0.84; 'subject:balls': 0.84; 'amongst': 0.91 |
| Date | Mon, 12 Sep 2011 08:47:22 -0700 (PDT) |
| From | "Dr. Phillip M. Feldman" <Phillip.M.Feldman@gmail.com> |
| To | python-list@python.org |
| Subject | Re: recursive algorithm for balls in numbered boxes |
| In-Reply-To | <a3b7c177-944c-4d86-9329-0a88fd410c67@y21g2000yqk.googlegroups.com> |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Content-Transfer-Encoding | 7bit |
| X-Nabble-From | Phillip.M.Feldman@gmail.com |
| References | <32440187.post@talk.nabble.com> <a3b7c177-944c-4d86-9329-0a88fd410c67@y21g2000yqk.googlegroups.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1038.1315842450.27778.python-list@python.org> (permalink) |
| Lines | 42 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1315842450 news.xs4all.nl 2405 [2001:888:2000:d::a6]:52740 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:13187 |
Show key headers only | View raw
Mark Dickinson-2 wrote: > > > This is a well-known trick: to divide 5 (unlabeled) balls amongst 3 > (labeled) boxes, you write down sequences of 5 o's and 2 x's, where > the o's represent the 5 balls and the 'x's represent dividers: > > ooxooxo -> [2, 2, 1] > xoooxoo -> [0, 3, 2] > > And 'combinations(7, 2)' yields successively all the possible > different placements for the 2 dividers in the 7 symbols. > > > This question seems to come up often enough (without the box size > limit twist) that maybe it would be useful to include something like > this recipe in the itertool documentation. > > > For getting this into itertools, I'd suggest opening a feature request > on bugs.python.org and assigning it to Raymond Hettinger. > > -- > Mark > -- > http://mail.python.org/mailman/listinfo/python-list > > You are correct--the case without capacity limits can be handled using the existing machinery in `itertools`. BTW--That trick with the dividers is discussed on page 38 of William Feller's classic text, "An Introduction to Probability Theory and Its Applications". As per your suggestion, I have opened a feature request and assigned it to Raymond. Thanks! -- View this message in context: http://old.nabble.com/recursive-algorithm-for-balls-in-numbered-boxes-tp32440187p32449079.html Sent from the Python - python-list mailing list archive at Nabble.com.
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
recursive algorithm for balls in numbered boxes "Dr. Phillip M. Feldman" <Phillip.M.Feldman@gmail.com> - 2011-09-10 17:43 -0700
Re: recursive algorithm for balls in numbered boxes Mark Dickinson <mdickinson@enthought.com> - 2011-09-11 08:08 -0700
Re: recursive algorithm for balls in numbered boxes "Dr. Phillip M. Feldman" <Phillip.M.Feldman@gmail.com> - 2011-09-12 08:47 -0700
csiph-web