Place n indistinguishable items into k distinguishable boxes

castironpi at gmail.com castironpi at gmail.com
Wed Feb 27 23:14:09 EST 2008


On Feb 27, 10:12 pm, castiro... at gmail.com wrote:
> On Feb 27, 8:40 pm, Michael Robertson <mcrobert... at hotmail.com> wrote:
>
>
>
>
>
> > Hi,
>
> > I need a generator which produces all ways to place n indistinguishable
> > items into k distinguishable boxes.
>
> > For n=4, k=3, there are (4+3-1)!/(3-1)!/4! = 15 ways.
>
> > (0,0,4)
> > (0,4,0)
> > (4,0,0)
>
> > (0,2,2)
> > (2,0,2)
> > (2,2,0)
>
> > (0,1,3)
> > (0,3,1)
> > (3,0,1)
> > (3,1,0)
>
> > (1,1,2)
> > (1,2,1)
> > (2,1,1)
>
> > The generator needs to be fast and efficient.
>
> > Thanks.
>
> Note that the boxes are indistinguishable, and as such, ( 1, 0, 3 ) ==
> ( 3, 0, 1 ), but != ( 3, 1, 0 ).  How so?- Hide quoted text -
>
> - Show quoted text -

Ah, correction, retracted.  -disting-uishable boxes.  Copy, but then,
where's ( 1, 0, 3 )?



More information about the Python-list mailing list