javascript,arrays,enumerate,cartesian,powerset

var obj = {"varA":[1,2,3], "varB":['good','bad'], "varC":[0,100], "varD":['low','med','high'] } // flatten the object into an array so it's easier to work with var obj2list = function(obj) { var list = []; for (var key in obj) { if (obj.hasOwnProperty(key)) { list.push({ name: key, val: obj[key] }); } } return list;...

For the specific case of a space of natural numbers, you want np.indices: >>> np.indices((4, 4)).reshape(2,-1).T array([[0, 0], [0, 1], [0, 2], [0, 3], [1, 0], [1, 1], [1, 2], [1, 3], [2, 0], [2, 1], [2, 2], [2, 3], [3, 0], [3, 1], [3, 2], [3, 3]]) (numpy actually...

algorithm,permutation,powerset

Algorithm to generate all possible permutations of a list? It's a complicated algorithm any way you want to do it, I think recursively is the fun way. The recursive way basically removes one element, calls the recursion on the shortened list, then returns the recursive result with the removed element...

c++,string,combinations,powerset,lexicographic

This is a simple recursive approach: #include <string> #include <iostream> using namespace std; void get( string str, string res ) { cout << res << endl; for( int i = 0; i < str.length(); i++ ) get( string(str).erase(i,1), res + str[i] ); } int main( int argc, char **argv) {...

Power set of a set A is the set of all of the subsets of A. Not the most friendly definition in the world, but an example will help : Eg. for {1, 2}, the subsets are : {}, {1}, {2}, {1, 2} Thus, the power set is {{}, {1},...

When you are appending to the result, this will invalidate iterators when the reallocation occurs and reallocation occurs when you exceed vector capacity. for(vector<int> subSet:result){ subSet.push_back(i); result.push_back(subSet); } If you reserve enough space in the vector result at the beginning via reserve () member function, it should work. I didn't...