Generating all combinations

Mensanator mensanator at aol.com
Thu Jun 4 07:00:26 CEST 2009

On Jun 3, 10:53�pm, Steven D'Aprano
<ste... at REMOVE.THIS.cybersource.com.au> wrote:
> On Wed, 03 Jun 2009 18:21:37 -0700, Mensanator wrote:
>
> [mass snippage]

> Settle down Mensanator! Don't take it so personally! You're sounding
> awfully agitated.

Don't worry, I'm not.

>
> Now that I've narrowed down what you actually meant, I'm happy to agree
> with you, at least informally.

>
> If I had a good use-case for dearrangements, or a fast, reliable
> implementation, then maybe I would.

*I* happen to have a good user-case for "partitions
of DEPTH indistinguishable items into WIDTH ordered
bins such that DEPTH >= WIDTH and each bin must contain
at least 1 item". That comes up in the Collatz
Conjecture, specifically, a list of WIDTH integers
that sums to DEPTH such that the list cannot be
empty nor contain any number less than 1.

Horribly important.

For example, 7 items into 4 bins would be:

import collatz_functions as cf
for i in cf.partition_generator(7,4):
print i

##  [1, 1, 1, 4]
##  [1, 1, 2, 3]
##  [1, 1, 3, 2]
##  [1, 1, 4, 1]
##  [1, 2, 1, 3]
##  [1, 2, 2, 2]
##  [1, 2, 3, 1]
##  [1, 3, 1, 2]
##  [1, 3, 2, 1]
##  [1, 4, 1, 1]
##  [2, 1, 1, 3]
##  [2, 1, 2, 2]
##  [2, 1, 3, 1]
##  [2, 2, 1, 2]
##  [2, 2, 2, 1]
##  [2, 3, 1, 1]
##  [3, 1, 1, 2]
##  [3, 1, 2, 1]
##  [3, 2, 1, 1]
##  [4, 1, 1, 1]

But, as you can see, I already know how to calculate
it and I doubt anyone but me would be interested in
such a thing.