Re: set partitioning

2006-05-02 Thread Boris Borcic
I wrote: > > def pickk(k,N,m=0) : > if k==1 : > return ((n,) for n in range(m,N)) > else : > return ((n,)+more for more in pickk(k-1,N,m+1) > for n in range(m,more[0])) > > def partitionN(k,N) : > subsets = [frozenset(S) for S in pickk(k,N)]

Re: set partitioning

2006-05-02 Thread Boris Borcic
[EMAIL PROTECTED] wrote: > For the list [1,2,3,4], I'm looking for the following for k = 2: > > [[1,2], [3,4]] > [[1,3], [2,4]] > [[1,4], [2,3]] > > for k = 3: > > [[1,2,3], [4]] > [[1,2,4], [3]] > [[1,3,4], [2]] > [[2,3,4], [1]] > def pickk(k,N,m=0) : if k==1 : return ((n,) for

Re: set partitioning

2006-05-02 Thread Edward Elliott
[EMAIL PROTECTED] wrote: > For the list [1,2,3,4], I'm looking for the following for k = 2: > > [[1,2], [3,4]] > [[1,3], [2,4]] > [[1,4], [2,3]] That's not what you asked for the first time. You said you wanted "m non-empty, disjoint subsets", but the subsets above are clearly not all disjoint;

Re: set partitioning

2006-05-01 Thread James Waldby
"[EMAIL PROTECTED]" wrote: > Can someone tell me of a good algorithm to partition a set of n > elements into m non-empty, disjoint subsets, where each subset has > size k? and later wrote in a separate post > Also, if I do not care about the number of subsets, what is a good > algorithm to partiti

Re: set partitioning

2006-05-01 Thread hymort
For the list [1,2,3,4], I'm looking for the following for k = 2: [[1,2], [3,4]] [[1,3], [2,4]] [[1,4], [2,3]] for k = 3: [[1,2,3], [4]] [[1,2,4], [3]] [[1,3,4], [2]] [[2,3,4], [1]] -- http://mail.python.org/mailman/listinfo/python-list

Re: set partitioning

2006-05-01 Thread Michael Ekstrand
On Mon, May 01, 2006 at 03:42:53PM -0700, [EMAIL PROTECTED] wrote: > Not quite what I'm looking for. I would like a list of all partitions > with each partition having k or less elements, not just one instance. def partition(S, k): parts = [] ct = 0 cp = [] for elem in S:

Re: set partitioning

2006-05-01 Thread [EMAIL PROTECTED]
Hello, Not quite what I'm looking for. I would like a list of all partitions with each partition having k or less elements, not just one instance. [EMAIL PROTECTED] wrote: > Something like this, or am I missing something? > > def partition(List, n, m, k): > if n!=m*k: > raise "so

Re: set partitioning

2006-05-01 Thread aaronwmail-usenet
Something like this, or am I missing something? def partition(List, n, m, k): if n!=m*k: raise "sorry, too many or too few elts" D = {} for x in List: D[x] = 1 if len(D)!=n: raise "sorry (2) you lied about the number" List2 = D.keys() resul

Re: set partitioning

2006-05-01 Thread [EMAIL PROTECTED]
Also, if I do not care about the number of subsets, what is a good algorithm to partition a set of n elements into non-empty, disjoint subsets of size k? -- http://mail.python.org/mailman/listinfo/python-list

set partitioning

2006-05-01 Thread [EMAIL PROTECTED]
Can someone tell me of a good algorithm to partition a set of n elements into m non-empty, disjoint subsets, where each subset has size k? -- http://mail.python.org/mailman/listinfo/python-list