mirror of
https://github.com/balkian/gists.git
synced 2024-12-17 20:18:12 +00:00
Add 'repos/9186599/' from commit '78198af80421c8a6ab12609bd58b3483a77da5d6'
git-subtree-dir: repos/9186599 git-subtree-mainline:44c3bd604a
git-subtree-split:78198af804
This commit is contained in:
commit
a55d007746
14
repos/9186599/Array combinations
Normal file
14
repos/9186599/Array combinations
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
a=set([1,2,3,4])
|
||||||
|
b=set([4,5,6,7])
|
||||||
|
c=set([7,8,9])
|
||||||
|
def array_combinations(*args):
|
||||||
|
combinations = [[i] for i in set(args[0])]
|
||||||
|
for arg in args[1:]:
|
||||||
|
tempcomb = []
|
||||||
|
for i in set(arg):
|
||||||
|
tempcomb += [c+[i] for c in combinations if i not in c ]
|
||||||
|
combinations = tempcomb
|
||||||
|
return combinations
|
||||||
|
res = array_combinations(a,b,c)
|
||||||
|
print res
|
||||||
|
print len(res)
|
11
repos/9186599/Array combinations as sets
Normal file
11
repos/9186599/Array combinations as sets
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
def array_combinations(*args):
|
||||||
|
combinations = set([frozenset([i]) for i in set(args[0])])
|
||||||
|
for arg in args[1:]:
|
||||||
|
tempcomb = []
|
||||||
|
for i in set(arg):
|
||||||
|
tempcomb += [frozenset(list(c)+[i]) for c in combinations if i not in c ]
|
||||||
|
combinations = set(tempcomb)
|
||||||
|
return [list(comb) for comb in combinations]
|
||||||
|
res = array_combinations(a,b)
|
||||||
|
print res
|
||||||
|
print len(res)
|
Loading…
Reference in New Issue
Block a user