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: 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" To: python-list@python.org Subject: Re: recursive algorithm for balls in numbered boxes In-Reply-To: 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> 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: 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 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.