From f191ccf557b5324f9589abb5fac9eab79ce3a303 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Fernando=20S=C3=A1nchez?= Date: Mon, 24 Feb 2014 03:18:39 -0800 Subject: [PATCH 1/4] --- Array combinations | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Array combinations diff --git a/Array combinations b/Array combinations new file mode 100644 index 0000000..65fe445 --- /dev/null +++ b/Array combinations @@ -0,0 +1,10 @@ +def array_combinations(*args): + combinations = [[i] for i in args[0]] + for arg in args[1:]: + tempcomb = [] + for i in arg: + tempcomb += [c+[i] for c in combinations if i not in c ] + combinations = tempcomb + return combinations +res = array_combinations(a,b,c) +print len(res) \ No newline at end of file From ba4bb85a92dfe611d71502123b9c91dbbdfd9ff1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Fernando=20S=C3=A1nchez?= Date: Mon, 24 Feb 2014 03:31:13 -0800 Subject: [PATCH 2/4] --- Array combinations | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Array combinations b/Array combinations index 65fe445..a265ab2 100644 --- a/Array combinations +++ b/Array combinations @@ -1,10 +1,11 @@ def array_combinations(*args): - combinations = [[i] for i in args[0]] + combinations = [[i] for i in set(args[0])] for arg in args[1:]: tempcomb = [] - for i in arg: + 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) \ No newline at end of file From 0dfa2fb28658b67c6bfd83b0ee58f9bcad7a38a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Fernando=20S=C3=A1nchez?= Date: Mon, 24 Feb 2014 03:32:08 -0800 Subject: [PATCH 3/4] --- Array combinations | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Array combinations b/Array combinations index a265ab2..8ef050e 100644 --- a/Array combinations +++ b/Array combinations @@ -1,3 +1,6 @@ +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:]: From 78198af80421c8a6ab12609bd58b3483a77da5d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Fernando=20S=C3=A1nchez?= Date: Mon, 24 Feb 2014 04:09:59 -0800 Subject: [PATCH 4/4] --- Array combinations as sets | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Array combinations as sets diff --git a/Array combinations as sets b/Array combinations as sets new file mode 100644 index 0000000..a843209 --- /dev/null +++ b/Array combinations as sets @@ -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) \ No newline at end of file