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)]
[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
[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;
"[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
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
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:
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
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
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
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
10 matches
Mail list logo