There are two letters "X" and "Y". A String of length N needs to be formed using those two letters. How many number of combinations that can be possible where N should start with "Y" and no two or more consecutive "X" will be there? Consider N = 7: I...

Other than doing this: from itertools import combinations def brute_force(x): for l in range (1,len(x)+1): for f in list(combinations(range(0,len(x)),l)): yield f x = range(1,18) len(list(brute_force(x))) [out]: 131071 How could I mathematically calculate the number of all possible combinations? Is there a way to do it computationally without enumerating the possible...

I would like to create all possible combinations of a binary vector made of a fixed number of 0 and 1. For example: dim(v)=5x1; n1=3; n0=2; In this case I'd like to have something like: 1,1,1,0,0 1,1,0,1,0 1,1,0,0,1 1,0,1,1,0 1,0,1,0,1 1,0,0,1,1 0,1,1,1,0 0,1,1,0,1 0,1,0,1,1 0,0,1,1,1 I found some help reading...

I want to get all combinations of of strings from a set of strings. For Example: permut = set() permut.add("D") permut.add("C") def getAllKombos(stuff): returnvalue = set() for L in range(0, len(stuff) + 1): for subset in itertools.combinations(stuff, L): for i in subset: x = x + (str(i)) returnvalue.add(x) x =...

I want to get all possible combinations of certain values present in a column range and print them in an excel sheet: Please note that the order of combination does not matter i.e AB=BA Here is an example of data in column1 for which combinations are to be found: F1...

I have to arrays with integers: int[] a={1,2,3,4,5}; int[] b={6,7}; I would like to generate an array, which contains pairs from the a and b arrays, in a random order, without duplicates. For example I would like to get the following result: c={(1,6),(2,7),(4,6),...} Thanks!...

There is a question I have had a problem doing. How many combinations of truth values for p, q, and r make this expression true? (p && !q) || (q || !r) I know that the answer is 7, but I don't know how they got the answer. I could...

suppose I have two arrays a and b: a=seq(2013,2015) b=c('-03-31','-06-30') I would like to combine each element in a with each in b. The result should be an array which looks like: "2013-03-31" "2013-06-30" "2014-03-31" "2014-06-30" "2015-03-31" "2015-06-30" How do I do this?...

I have array symbols what I want replace, but I need generate all possibillity $lt = array( 'a' => 'ą', 'e' => 'ę', 'i' => 'į', ); For example if I have this string: tazeki There can be huge amount of results: tązeki tazęki tązęki tazekį tązekį tazękį tązękį My...

assume that I have two lists of the same length. l1 <- list(c("a", "b", "c"), "d") l2 <- list(c("e", "f"), c("g", "h", "i")) Each row/element of a list can be seen as a specific pair. So in this example the two vectors c("a", "b", "c") c("e", "f") "belong together" and...

Given an instance of List<E>, using Java 8 features, how is it possible to build a List<List<E>> enumerating all possible combinations of k elements of the original List?

I have a list of numbers and I wish to return a 2D list, preferably ordered from biggest to smallest (although I can do this afterwards), of all the possible combinations of multiplication (to yield the product of the original list) using all the elements of the list, without duplicates....

so here is my problem: I need a function that given a string "qwer" of random length can select and put in an array all the possible sequences of characters long from 1 up to the length of the string. I am sorry, it is difficult to explain, but i...

I will try to better explain my needs. I need to generate from scrach, a multidirectional array who contain many array. The inner array must be array containing 7 boolean value. I need to have all the combinaisons possible of 7 boolean values. With 7 cases, it make 128 inner...

In haskell, given a list of elements, xs, the simplest way to iterate over all pair permutations with repetitions is: [(x,y) | x <- xs, y <- xs] I wish to be able to do the same, but only on combinations. If x and y were comparable, I could do...

I am trying to write a piece of code to traverse all the possible parameter combinations for a algorithm with python. import numpy as np parameter={'alpha1':np.linspace(0.3,0.4,10),'alpha2':np.linspace(0.9,2,100),...'alpha5':np.linspace(5,10,100)} the problem is that I just couldn't write 5-nested for loop.Can anyone give a demo on how to write a recursion function to give...

I've got a set of inputs on a form that are watched for interactivity, validation, or both. In the case of both, I'm not sure how to add the second set of functionality without overriding the prior assignment. Here's an example. I've got a field that should be watched for...

I want to list all possible pairs of the integers [1, n] with a large n. I find myself looking for the fastest option. This is what I've come up with so far. Matlab's nchoosek and combnk methods recommend n<15 for listing all possible combinations because of the explosive number...

Right now I'm trying to write a function that takes an array and an integer n, and gives a list of each size n combination (so a list of int arrays). I am able to write it using n nested loops, but this only works for a specific size of...

Below is my code import itertools a = [1,2,3] for i in itertools.combination_with_replacement(a,3): print i Output (1, 1, 1),(1, 1, 2) (1, 1, 3),(1, 2, 2) (1, 2, 3),(1, 3, 3) (2, 2, 2),(2, 2, 3) (2, 3, 3),(3, 3, 3) Only 10 result is print out, but by formula,...

I have two columns for example, I want to list all the rows where the items in ROW A appears more than once in Column A, but have distinct values in Column B. So far I have not figured out an answer Column A Column B Apple x Banana a...

I have a string in python and a dictionary of 'rules', or possible alterations to the string. For example, one rule might have a key of 'he' and a value of 'e', or a key of 'll' and a value of 'l'. These rules would mean that any occurrence of...

Assume in R we have three columns. The first is a random sample of 1:4 with replacement. The second is 1:4 repeating as needed. The third is just an index. The result should output a pasted combination of the numbers where order doesn't matter and give a count. Please, note...

How can I find all combinations of a vector and it's negatives in R? I.E. x <- c(1,2,3,4) will output (1,2,3,4), (-1,2,3,4), (1,-2,3,4), (1,2,-3,4), (1,2,3,-4), ... , (-1,-2,-3,-4) ...

I have an existing database with a table that I need to alter. Due to some recent changes requested, I need to take two columns out of a table and put the data from those two columns into an existing column in the table. Thankfully, they are all Varchar type...

Let's say we have the following dataset set.seed(144) dat <- matrix(rnorm(100), ncol=5) The following function creates all possible combinations of columns and removes the first (cols <- do.call(expand.grid, rep(list(c(F, T)), ncol(dat)))[-1,]) # Var1 Var2 Var3 Var4 Var5 # 2 TRUE FALSE FALSE FALSE FALSE # 3 FALSE TRUE FALSE FALSE...

I am new to JS and trying to learn on my own - thanks for any help! I am trying to have a simple program respond to a click differently depending on what other key is pressed at the time of the mouse click. I have searched far and wide...

I need to apply all the combinations of the elements of a vector to a particular function, and use these elements as inputs for this function as well. I would like it to be somewhat fast, but any combination of apply and its different flavors has proved fruitless so far....

Hi so I'm working with python and I'm trying to write a method where given a string, it would find every combination of that string and append it to a list. I'll give the string and show the outcome that I want. string: x = 'god' outcome: lst = ['g',...

Let's say I have set = [1, 2, 3, 4, 5, 6, 7] I'd like the following in return [1, 2, 3, 4, 5] [4, 3, 2, 1, 6] [7, 5, 1, 3, 2].......... Essentially, as the title states I'm looking to generate specific sized combinations from an array but...

Input is an array of 'n' length. I need to generate all possible combinations of array elements, including all combinations with fewer elements from the input array. IN: j='{A, B, C ..}' OUT: k='{A, AB, AC, ABC, ACB, B, BA, BC, BAC, BCA..}' With repetitions, so with AB BA.. I...

I have an array of floats of unknown length. The numbers range from 0-1000. I'm looking to generate every possible addition combination from those numbers that is less than a user defined value and append them in another list. for example, if numlist =[200,350,510] and the defined maximum is 1200,...

I have two text input. Like This: So, I have some kind of dynamic ajax search. I pass the input data and make two different mysql select. Something like this: Table finalmap - SELECT 1 id -------- latitud-----longitud--- 1 | 6.2523915 | -75.5737028 | 2 | 6.2640349 | -75.5990783 |...

Supposing I have these 3 arrays $array1 = array(1,2); $array2 = array(4,5); $array3 = array(7,8); I need this output 1 4 7 1 4 8 1 5 7 1 5 8 2 4 7 2 4 8 2 5 7 2 5 8 One of my problems is that my...

I have a column vector x made up of 4 elements, how can i generate all the possible combinations of the values that x can take such that x*x' is less than or equal to a certain value? note that the values of x are positive and integers. To be...

I am trying to implement a method to get all subset of a set. I understand the logic of doing that. i.e. Subset(n) = n + Subset(n-1), but the code I wrote keep printing out the wrong answers. Here is my code: void subset(vector<int> &input, vector<int> output, int current) {...

I am trying to perform aggregation (basic sum) on geospatial data that contains directionality information. I am trying to collapse the directionality dimension. So if A -> B and B -> A, then count both. I have the following data: u <- data.frame(str_statn=c(42, 106, 3, 6, 4), end_statn=c(106, 42, 6,...

I'm trying to create a table that would enforce a unique combination of two columns of the same type - in both directions. E.g. this would be illegal: col1 col2 1 2 2 1 I have come up with this, but it doesn't work: database=> \d+ friend; Table "public.friend" Column...

This post shows how to write an algorithm to spit out, at one time, all combinations of k elements from n, avoiding permutations. But how would one write an algorithm that, on demand, gives the next combination (obviously, without precomputing and storing them)? It would be initialized with the ordered...

I want to create a matrix from all combinations of elements of one vector that fulfill a condition For example, I have this vector a = [1 2 3 4 5] and want to create a matrix like a = [1 0 0 0 0; 1 2 0 0 0;...

This algorithm's purpose is to generate a list of sequences of trips. Each trip has a start point and and end point. The user specifies both of those, and every sequence in the list returned by the algorithm must ultimately begin with a trip that has the specified start point...

a = [1,2,3,4].combination(3).to_a returns [[1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4]] What do I need to do to get the following combination of the array shown below [["1a","1b"],2,3,4] should be => [["1a", 2, 3], ["1a", 2, 4], ["1a", 3, 4],["1b", 2, 3], ["1b", 2, 4],...

I have to generate a list of all possible combinations of numbers and letters of length three. The catch is on the first two characters can be letters or numbers, and the third one can only be numeric. For example: AA1, AA2, AA3 .... FC7 ... 001, 002 ... 365)...

I'm struggling with creating a way to identify key combinations. Before I can even set any booleans, I noticed that certain key combinations lead to ignoring other keys. package question; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import javax.swing.AbstractAction; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.KeyStroke;...

I'm trying to create a function that is able to go through a row vector and output the possible combinations of an n choose k without recursion. For example: 3 choose 2 on [a,b,c] outputs [a,b; a,c; b,c] I found this: How to loop through all the combinations of e.g....

I have a table that looks like this: Indikaatori nimi Alamkriteerium Kriteerium Skoor 1 Indikaator 1 1.1 1 100 2 Indikaator 2 1.2 1 100 3 Indikaator 3 1.3 1 100 4 Indikaator 4 1.1 1 0 5 Indikaator 5 2.1 2 0 6 Indikaator 6 2.1 2 0 ......

My approach to the problem was as follows- a=[ ] for i in range(7): a.append([0]*7) c=dict() for i in range(7): for j in range(7): a[i][j]=(i,j) for i in range(7): for j in range(7): c[i+j]=tuple((i*j+j+c)) print c But this produces: {0: (0, 0), 1: (1, 0), 2: (2, 0), 3:...

Hi I have 4 strings to execute combinations- 1)PES 2)PEA 3)PAL 4)PSL I have to write a script to perform combination (combinatorial - ncr formula) such that I only need combination with following algorithm If I have PAL in the combination output then keep PAL only and remove other string...

I need to generate complete set of tokens of size exactly equal to 8.Each bit in the token can assume values from 0 - 9 and A -Z. For example- The following are valid tokens: 00000000 0000000A 000000H1 Z00000XA So basically i want to generate all tokens from 00000000 to...

I want to write a function to select combination of k element from list of n element.I have the given source file in pdf form that i converted in text.And i got the following list .I was trying to use dfs to find the combinations but there are constraint that...

I'm trying to implement an algorithm to get all combinations of k elements out of a set of n elements where the difference between two consecutive combinations are maximized (so kind of reverse Gray codes). In other words, the combinations should be ordered to avoid elements from appearing twice in...

Following code tries to compute the nCr values for the various values of given n and here r varies from 0 to n. The input is in the following format :- Input Format The first line contains the number of test cases T. T lines follow each containing an integer...

I'm trying to resolve, obtain a algorithm, for the problem that follows: Having a matrix with n columns and each column is the same length, what's the minimum number of columns so I can get all values of the matrix. Ex: Matrix with 4 columns and 3 rows with values...

I have two arrays [a0 b0 c0] [a1 b1 c1] I want to calculate all the possible sums between the two. A possible sum consists of only 1 element for each column slot. For example a possible sum is a0 + b1 + c1 or a1 + b1 + c1...

I assume this is a classic question but I did not find an answer that fit my problem. I have two vectors of 'MyObject' and I want to iterate through all possible combination of the elements of the first vector with those of the second one, and treat all cases...

myMatrix <- matrix(c(1,2,3,4,5,6),2,3, byrow=T) # line 1 exp.myMatrix <- function(myMatrix) { # line 2 for (rownum in 1:nrow(myMatrix)) assign(paste("R",rownum, sep=""), myMatrix[rownum,]) # line 3 Combinations <- do.call(expand.grid, lapply(ls(pattern='^R\\d$'), get)) # line 4 rm(list=ls(pattern='^R\\d$')) # line 5 return(Combinations) # line 6 } # line 7 Combinations <- exp.myMatrix(myMatrix) # line...

Given a finite set of bins and objects, where the bins are of infite size (there is no limit to the number of objects they can hold. What is an efficient algorithm to compute all the possibilities of objects in bins. For example: Lets say we have bins: B1, B2...

i have 4 sets each contain 6 elements from which I want to generate all possible vectors of size 8 were the first two elements are from set1 second 2 from set2 third 2 from set3 forth 2 from set4 without repetition in the points taken from each set such...

i have been trying to find a solution to this for several months now. it is for an art project of mine. so far i could find partial python and c solutions, but they are of no use for my case... i need a working solution either in PHP or...

I'm trying to create a brute force that will work on a specific files password. I'm not sure how to get this code to work. This is what I have so far. This code produces the correct possible combinations for the password but I am not sure how to implement...

In a project assignment I have I want the one part of the PRIMARY KEY to reset after the other part changes value. For example: CREATE TABLE shopping_center( centerID INTEGER AUTO_INCREMENT, centerName CHAR(50), CONSTRAINT center_PK PRIMARY KEY(centerID)); CREATE TABLE staff( staffID INTEGER AUTO_INCREMENT, centerID INTEGER, name VARCHAR(50), CONSTRAINT staff_PK PRIMARY...

I'm trying to write a C program to find all the combinations of an given array and a specified length. This is what I've done so far.. #include <stdio.h> void com(int* a, int* t, int len, int i) { int j, k; if(len == 0) { for(k=0;k<3;k++) { printf("%d ",t[k]);...

usually for lottery combinations the formula is "n! / (k!*(n-k)!)", e.g., for a 6/49 game it is "49!/(6!*(49-6)!)" is there a formula to calculate the same with m FIXED values (e.g., the numbers 1, 2, 3, and 4 are fixed) - 2 numbers are free for choice i thought the...

I have to make a function that takes 3 inputs like e0, e1 and e2. The function will have 2 outputs x and y. x will be the combinations of e0, e1 and e2. y will be a column vector containing sums of columns of x. The following conditions must...

I'm quite knew to JavaScript (been studying it only for less than a week now) and am having problems computing the sum of the values in the subarrays I generated from a certain array. I was able to do that using this function: function getSubs(arr) { var newarr = [];...

I want to generate a list of all unique ways to choose two from a list of numbers in Haskell. So from the list [1,2,3] I would like [[1,2],[2,3],[1,3]]. Order is not important so I want to avoid producing both [1,2] and [2,1] for example. My current solution is: pairs...

I am new to permutations and combinations. I am provided with the number n and I can make a number with the help of n+1 digits which are 0,1,...n. I need to find in how many ways I can make the sum n by putting these n+1 digits in n...

I have to perform a task. pls help me. İ want a c sharp console application that can find every combination of some numbers but only writes if they can divide by 3. We have 15 card in a bag. we will take 3 cards randomly(without replacement) . After that...

I just did a Top Coder SRM where there was a question I had problem solving. I am trying to searching online for details of the algorithm but I can't seem to find it. The question went around the lines of: You have an array, for example [12, 10, 4]...

I have to find nCrmod M where M is not a prime number. How can find that. I know that i need to find the inverse modulo but how it is going to be implemented if the number M is non-prime.

I have a list: a = range(2) and I am trying to get the list's contents binned into n(=3) bins, in all possible ways, giving (order not important): [[[],[0],[1]], [[],[1],[0]], [[],[0,1],[]], [[],[],[0,1]], [[0],[1],[]], [[0],[],[1]], [[1],[0],[]], [[1],[],[0]], [[0,1],[],[]]] So far, I have been using the sympy.utilities.iterables library, firstly to get all...

Setup: I have a list of numbers that represent a Binary tree. The first number is treated differently than some of the rest, it is the root. Out of "the rest" of the numbers, some will be higher than the root, some will be lower. Higher numbers are ordered to...

I have a list of values [1,2,3,4,5,...], I want to return a list of all possible connected combinations using list comprehensions, numpy or whatever works. By connected, i mean that pairs of items in the list should maintain their adjacencies in the combinations (not necessarily that integers with adjacent values...

There are 6 seats and 4 persons, for which seats must be allocated according to some optimality criterion. For example: Allocation 1: _ _ _ _ _ _ 1 2 3 4 Allocation 2: _ _ _ _ _ _ 1 3 2 4 ... Question 1: Which combinatorics problem...

I'm working on a problem in Java to find all possible combinations given an arbitrary starting array, by decrementing the values one at a time of each item in the array until the value 1 is reached at each index. I've started on the below test case but haven't got...

Can't figure out how to make combinations of arrays without repetitions. INPUT is an array of n variables LIKE '{A,B,C,D,E}' Variable A is always single array LIKE '{"A"}' or '{"D,C"}' or '{"D,A,B"}' etc.. What I need is to combine INPUT with A(i) EXAMPLE: 1. A = '{"B"}' --> att='{"B,A","B,C","B,D","B,E"}' 2....

I tried to create the code to generate all possible combination of the given string in the lexicographical order: The code that I wrote is: void get(char *n) { int l=strlen(n); sort(n,n+l); int k=0,m,i,j,z; while(k<l) { m=k; for(i=k;i<l;i++) { for(j=k;j<=i;j++) cout<<n[j]; cout<<"\n"; } for(z=m+2;z<l;z++) cout<<n[m]<<n[z]<<"\n"; k++; } } int main()...

I want to create a list of possible combinations of a list of lists (example will explain better) list=[[a,b],[c,d],[f]] The result should be acf adf bcf bdf The length of the list can vary, and the length of the lists within the variable list can also vary. How would I...

With this function, i can have all possibles combination (with repetition). But, i doesn't want to put a string, i would like to put an array or something like this. Maybe if I can put in $source="apple,patatoes,orange"; And split in the function to have this result : apple,apple apple,patatoes apple,orange...

This question already has an answer here: Generating a n-ary Cartesian product example 1 answer I just want to get cartesian product of numbers in a single list with specified number in C#. In below, I gave some examples of actually what I want get to: List<int> numbers =...

There is a classic Knapsack problem. My version of this problem is a little different. Given set of items, each with a mass, determine the number of combinations to pack items so that the total weight is less than or equal to a given limit. For example, there is 5...