I want to find a set defining algorithm A
to find all groups of subsets that satisfy the following condition:
x ∪ y ∪ .... z = A, where x, y, ... z ∈ Group
and
∀ x, y ∈ Group: x ⊆ A, y ⊆ A, x ∩ y = ∅ = {}
and
∀ x ∈ Group: x! = ∅
Note. I hope to define it correctly, I do not like mathematical symbols.
I made the following approach only to search for groups of two subsets:
from itertools import product, combinations
def my_combos(A):
subsets = []
for i in xrange(1, len(A)):
subsets.append(list(combinations(A,i)))
combos = []
for i in xrange(1, 1+len(subsets)/2):
combos.extend(list(product(subsets[i-1], subsets[-i])))
if not len(A) % 2:
combos.extend(list(combinations(subsets[len(A)/2-1], 2)))
return [combo for combo in combos if not set(combo[0]) & set(combo[1])]
my_combos({1,2,3,4})
I get the following conclusion: these are all groups consisting of two subsets
[
((1,), (2, 3, 4)),
((2,), (1, 3, 4)),
((3,), (1, 2, 4)),
((4,), (1, 2, 3)),
((1, 2), (3, 4)),
((1, 3), (2, 4)),
((1, 4), (2, 3))
]
..... but groups of one, three, four subsets ....
Question:
How can I find a general solution?
For example, the following expected result:
my_combos({1,2,3,4})
[
((1,2,3,4)),
((1,2,3),(4,)),
((1,2,4),(3,)),
((1,3,4),(2,)),
((2,3,4),(1,)),
((1,2),(3,4)),
((1,3),(2,4)),
((1,4),(2,3)),
((1,2),(3,),(4,)),
((1,3),(2,),(4,)),
((1,4),(2,),(3,)),
((1,),(2,),(3,4)),
((1,),(3,),(2,4)),
((1,),(4,),(2,3)),
((1,),(4,),(2,),(3,))
]