diff --git a/repos/9186870/array_combination.ipynb b/repos/9186870/array_combination.ipynb new file mode 100644 index 0000000..2907865 --- /dev/null +++ b/repos/9186870/array_combination.ipynb @@ -0,0 +1,38 @@ +{ + "metadata": { + "name": "Untitled0" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "code", + "collapsed": false, + "input": "a=set([3,4])\nb=set([3,7])\nc=set([4])\n", + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 6 + }, + { + "cell_type": "code", + "collapsed": false, + "input": "def array_combinations(*args):\n combinations = [set([i]) for i in set(args[0])]\n for arg in args[1:]:\n tempcomb = []\n for i in set(arg):\n for c in combinations:\n c.update([i])\n tempcomb.append(c)\n if tempcomb:\n combinations = tempcomb\n return combinations\nres = array_combinations(a,b,c)\nprint res\nprint len(res)", + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": "[set([3, 4, 7]), set([3, 4, 7]), set([3, 4, 7]), set([3, 4, 7])]\n4\n" + } + ], + "prompt_number": 25 + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/repos/9186870/frozen_combination.py b/repos/9186870/frozen_combination.py new file mode 100644 index 0000000..d8e193f --- /dev/null +++ b/repos/9186870/frozen_combination.py @@ -0,0 +1,13 @@ +def frozen_combination(*args): + combinations = set([frozenset(),]) + for arg in args: + tempcomb = set(frozenset(),) + for i in set(arg): + tempcomb.update(set([frozenset(list(c)+[i]) for c in combinations if i not in c])) + if len(tempcomb) > 0: + combinations = tempcomb + return combinations +# return [set(comb) for comb in combinations] # for sets instead of frozensets +res = frozen_combination(a,b) +print res +print len(res) \ No newline at end of file