combinations

Vb.net all combinations

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-11 07:22:24
问题 I have 6 items which have to be combinated, items listed: ( this is an example) Ape Cow Deer | Small deer | Big deer sheep so 'deer' has 2 subitems. these items are all in an list listed like this: ape cow {deer | small deer | big deer} sheep so you can see which item has more items. what i want is all those combinations: ape cow deer sheep ape cow small deer sheep ape cow big deer sheep ( sometimes there are more then 6 items, sometimes there are less. Is someone who can help me with this?

Python: find all possible word combinations with a sequence of characters (word segmentation)

时光毁灭记忆、已成空白 提交于 2020-01-11 06:17:08
问题 I'm doing some word segmentation experiments like the followings. lst is a sequence of characters, and output is all the possible words. lst = ['a', 'b', 'c', 'd'] def foo(lst): ... return output output = [['a', 'b', 'c', 'd'], ['ab', 'c', 'd'], ['a', 'bc', 'd'], ['a', 'b', 'cd'], ['ab', 'cd'], ['abc', 'd'], ['a', 'bcd'], ['abcd']] I've checked combinations and permutations in itertools library, and also tried combinatorics. However, it seems that I'm looking at the wrong side because this is

All combinations of all sizes?

限于喜欢 提交于 2020-01-10 04:26:05
问题 There are thousands of results on SO when I search for "vector combinations in R" but I can't find the answer to my question. Apologies if it is a duplicate: I have a vector (1,2,3,4) and I want to find all combinations (n choose 2) to (n choose n). In other words, for this vector I would want: 1,2,3,4 1,2,3 1,2,4 1,3,4 2,3,4 1,2 1,3 1,4 2,3 2,4 3,4 And hopefully the code would be generalizable so that once I have a larger vector, it would be able to generalize. Thanks! 回答1: If you prefer

Numpy: efficient way to generate combinations from given ranges

冷暖自知 提交于 2020-01-09 08:04:08
问题 I have a n-dimension array as shown below: np.array([[0,3],[0,3],[0,10]]) In this array, the elements denote the low and high values. Ex: [0,3] refers to [0,1,2,3] I need to generate a combination of all values using the ranges given as above. For example, I want [0,0,0], [0,0,1] ... [0,1,0] ... [3,3,10] I have tried the following to get what I want: ds = np.array([[0,3],[0,3],[0,10]]) nItems = int(reduce(lambda a,b: a * (b[1] - b[0] + 1), ds, 1)) myCombinations = np.zeros((nItems,)) nArrays

How to structure a cell to store values in a specific format in Matlab?

ε祈祈猫儿з 提交于 2020-01-07 02:44:07
问题 I have a code that looks for the best combination between two arrays that are less than a specific value. The code only uses one value from each row of array B at a time. B = 1 2 3 10 20 30 100 200 300 1000 2000 3000 and the code i'm using is : B=[1 2 3; 10 20 30 ; 100 200 300 ; 1000 2000 3000]; A=[100; 500; 300 ; 425]; SA = sum(A); V={}; % number of rows for cell V = num of combinations -- column = 1 n = 1; for k = 1:length(B) for idx = nchoosek(1:numel(B), k)' rows = mod(idx, length(B)); if

How to make a combination of strings in C#?

删除回忆录丶 提交于 2020-01-06 13:53:28
问题 I need to make a combinaion of Stings "a" "b" "c" "d". I've tried putting them in a list then parsing a foreach methord through them, but to no avail. What else can I do? 回答1: I will give you the logic. Create a List<String> and then go on adding each string to it. List<String> s = new List<String>(); s.add("a"); s.add("b"); s.add("c"); s.add("d"); Once you added all the strings, then generate a random number between minimum and maximum index like this : private int RandomNumber(int min, int

Find the combination that minimizes a cost function

ぃ、小莉子 提交于 2020-01-06 08:45:08
问题 I am facing a problem and I would be grateful to anyone that could help. The problem is the following: Consider that we have a vector D = [D1;D2;D3;...;DN] and a set of time instances TI = {t1,t2,t3,...,tM} . Each element of vector D , Di , corresponds to a subset of TI . For example D1 could correspond to time instances {t1,t2,t3} and D2 to {t2,t4,t5} . I would like to find the combination of elements of D that corresponds to all elements of TI , without any of these being taken into account

Creating combination of numbers

[亡魂溺海] 提交于 2020-01-06 08:29:09
问题 Task is to find the permutations of numbers {1,2,3...N}. N <=16. The problem is in conditions: each number must be used only one time and permutation should be of N-size . And the each permutation should be array, because it will be tested. As input is given one permutation. The main task is to find all the permutations, that have the same set of difference as the first one has. For example, is given 12 3 6 1 9 11 8 5 2 4 7 10 Difference is -9,3,-5,8,2,-3,-3,-3,2,3,10 So, there are 12

Changing value when multiple rows/columns combined do not meet a requirement

安稳与你 提交于 2020-01-06 04:08:05
问题 Relatively new to R, working on a project with millions of rows so I made this example: I've got a matrix with three different rows of data. If the combination of [,1][,2][Farm] has less then two observations in total, the [Farm] value of that row gets changed to q99999. This way they fall in the same group for later analysis. A <- matrix(c(1,1,2,3,4,5,5), ncol = 7) B <- matrix(c(T,T,F,T,F,T,T), ncol = 7) C <- matrix(c("Req","Req","Req","fd","as","f","bla"), ncol = 7) AB <- rbind.fill.matrix

How to compute derangement (permutation) of a list with repeating elements

放肆的年华 提交于 2020-01-06 01:18:48
问题 I have a list with repeating elements, i.e. orig = [1,1,1,2,2,3] . I want to create a derangement b = f(orig) such that for every location value in b is different from value in orig : b[i] != orig[i], for all i I know a solution when all element in orig are unique, but this is a harder case. Developing a solution in python, but any language will do. 回答1: The not so-efficient solution is clearly import itertools set([s for s in itertools.permutations(orig) if not any([a == b for a, b in zip(s,