combinations

Finding All Combinations (cartesian product) of list values in vb.net

 ̄綄美尐妖づ 提交于 2019-12-12 17:09:39
问题 How can I produce all of the combinations of the values in N number of vb list of variable lengths? Let's say I have N number of vb lists, e.g. first = {'a', 'b', 'c', 'd'} second = {'e'} third = {'f', 'g', 'h', 'i', 'j'} (Three list in this example, but its N number of lists for the problem.) And I want to output all the combinations of their values, to produce a list of lists in the order. { {a,e,f} {a,e,g} {a,e,h} {a,e,i} {a,e,j} {b,e,f} {b,e,g} .... {d,e,j} } 回答1: A simple way to

R - generate all possible pairwise combinations of binary vectors

╄→гoц情女王★ 提交于 2019-12-12 15:11:52
问题 I am looking for a smart way to generate all pairwise combinations of two vectors of length n, where only one value is not zero. For now I am doing something quite desperate with loops through each combination with: n <- 3; z <- rep(0,n); m <- apply(combn(1:n,1),2,function(k) {z[k]=1;z}) but there must be a better way without loops? This is what I'm after for example for n=3: [,1] [,2] [,3] [1,] 1 0 0 [2,] 0 1 0 [1,] 1 0 0 [2,] 0 0 1 [1,] 0 1 0 [2,] 1 0 0 [1,] 0 1 0 [2,] 0 0 1 [1,] 0 0 1 [2,]

Create all possible ways of putting n users into k groups

故事扮演 提交于 2019-12-12 14:33:48
问题 Given n users (u_1, u_2,..., u_n) and k groups (g_1, g_2, ..., g_k), create all possible combinations of all groups. basically, in the end, each combination is a Map<Integer,Integer>, where the first Integer is user ID, and the second Integer is group ID.For example, [(u_1,g_1), (u_2,g_1)....,(u_n, g_1)] is one possible combination. There will be k^n combinations. I searched and saw similar problems, but they do have some extra conditions that do not apply for my problem. In my case, there is

R item combinations

烂漫一生 提交于 2019-12-12 13:31:54
问题 I'm using R and want to find the most common pairs between consumers. consumer=c(1,1,1,1,1,2,2,2,2,3,3,4,4,4,4,5) items=c("apple","banana","carrot","date","eggplant","apple","banana","fig","grape","apple","banana","apple","carrot","date","eggplant","apple") shoppinglists <- data.frame(consumer,items) Is there a way to see that "apple"+"banana" appears on three lists (consumers 1,2 and 3) and "apple"+"carrot" appears on two lists (consumers 1 and 4)? 回答1: You can see that information here: tbl

How to generate lists from a specification of element combinations

纵然是瞬间 提交于 2019-12-12 13:23:07
问题 I want to generate a bunch of lists using combinations of elements specified in a form like the following: [[10, 20], [30, 40], [50, 60]] This means that the values available for the first element are 10 and 20, the values available for the second element are 30 and 40 and so on (I've used just two element options for each element for brevity; there could be more than that). I want to use this specification to generate all lists using the combinations of these elements (including the

How to Generate all k-elements subsets from an N-elements set recursively in Java

南楼画角 提交于 2019-12-12 13:07:43
问题 So I am stuck with this problem of trying to find all k-elements subsets from a given N-elements set. I know what the total number of k-subsets is using the formula C(n,k)=C(n-1, k-1)+C(n-1, k) and I also have an idea how to do it in a iterative manner, but I get stuck when I try to think of a recursive solution. Can anyone give me a hint? Thanks! 回答1: For each element of the set, take that element, then add in turn to that all (k-1) subsets of the remaining N-1 element set. "It was a dark

Efficiently creating a sequential wordlist from charset

非 Y 不嫁゛ 提交于 2019-12-12 12:26:36
问题 I need to find an efficient way to create a list of sequential words created from a given charset in C/C++. Let me give you an example: If the charset is "abc", the algorithm should output: a b c aa ab ac ba bb bc ca cb cc aaa aab ... I have some ideas, but all are require too much maths and I really need a fast solution. Who's got an idea? 回答1: #include <stdio.h> #include <string.h> char* numToColumn(int n, char* outstr, const char* baseset){ char* p = outstr; int len; len = strlen(baseset);

Go Programming: Generating Combinations

天大地大妈咪最大 提交于 2019-12-12 12:19:29
问题 This is homework I'm working on a project, and a very small (very small, once I get this working...it's basically the pre-req for the rest of the project) part of it is to generate some combinations using a Go routine. The code I have is thusly: package bruteforce // GenerateCombinations is an iterator function. Given an alphabet and a // length, it will generate every possible combination of the letters in // alphabet of the specified length. // // It is meant to be consumed by using the

Find Most Frequent Combination within a Vector by Group

≯℡__Kan透↙ 提交于 2019-12-12 10:39:59
问题 I have a table with two columns namely id and item : df <- data.frame(id=c(1,1,2,2,2,2,3,3,3,4,4,4,4,4),item=c(1,2,3,1,2,3,4,1,2,3,1,2,1,2)) I want to find the most frequent combination (order doesn't matter) of 3 items per id . So basically, n choose r where n = number of items within id and r = 3 . The number of items per id varies - some have more than 3, some have less. I am new to R and read about combn and expand.grid , but I don't know how to use them in my case (to work within each id

Use CUDA to compute all possible combinations of words?

孤人 提交于 2019-12-12 09:26:46
问题 I want to find combination of all possible words that could be formed from a given tile set of 11 words. Is it possible to do that on CUDA? If yes than how. Thanks! 回答1: Yes, you can do permutations in CUDA, in fact, sr. Wong Shao Voon has an implementation of a Permutations algorithm with CUDA and OpenCL. He did not use String as you want, but this is not a major problem you just have to make a method that converts the symbols that he used (letters) to yours (words) after the algorithm is