Created
May 9, 2016 12:52
-
-
Save qbx2/1296194ed9b4af3daa601c324ed4215f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def k_subset(s, k): | |
if k == len(s): | |
return (tuple([(x,) for x in s]),) | |
k_subs = [] | |
for i in range(len(s)): | |
partials = k_subset(s[:i] + s[i + 1:], k) | |
for partial in partials: | |
for p in range(len(partial)): | |
k_subs.append(partial[:p] + (partial[p] + (s[i],),) + partial[p + 1:]) | |
return k_subs | |
def uniq_subsets(s): | |
u = set() | |
for x in s: | |
t = [] | |
for y in x: | |
y = list(y) | |
y.sort() | |
t.append(tuple(y)) | |
t.sort() | |
u.add(tuple(t)) | |
return u | |
x=[1,2,3,4,5,6,7] | |
p=list(uniq_subsets(k_subset(x, i)) for i in range(1,len(x)+1)) | |
r=[(1,2),(1,3),(1,4),(1,7),(2,3),(2,4),(2,5),(2,7),(3,4),(3,6),(3,7),(4,5),(4,6),(5,6),(5,7),(6,7)] | |
answer = [] | |
for p_i in p: | |
for p_i_method in p_i: | |
#print('p_i_method',p_i_method) | |
for p_i_n in p_i_method: | |
#print('p_i_n',p_i_n) | |
flag = True | |
for rr in r: | |
if rr[0] in p_i_n and rr[1] in p_i_n: | |
flag = False | |
break | |
if not flag: | |
break | |
#print(flag) | |
if flag: | |
answer.append(p_i_method) | |
for ans in answer: | |
print(ans) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
output