Questions tagged [combinations]

A combination is a selection of objects from a larger collection in no particular order.

4,124 questions
11 views

How to subset comparisons of list tuples in a combination loop

I have a .txt file that contains 100 rows and 500 columns. Each row has a single integer value for each column. (ie. 1 0 1 2 0 2 1 0...). For each row, I want to compare each column to every other ...
26 views

How to get the all the combinations of two columns? (Python)

[Update: I want the outcomes, not the fixtures. I've added code for my points table, which shows the current table, based on which I want to determine the probability of a team being in the top 4] I'...
115 views

Possible string permutations of mixture of multiset and set

I am trying to get all possible combinations of a char*. This string consits of four values: two numbers and two different letters. For example: char *text ="01ab"; There should be so different ...
59 views

Combinations of a group into multiple groups without repetition

We have a list of elements [A,B,C,D,E] and 3 groups to combine those elements, I would like to print a list of all unique combinations without repetition for those 3 groups. Only groups of lengths [2,...
40 views

How to combine strings in rows based on position condition

It proved difficult to find search terms for this kind of question. I need to write a script that can make all combinations of strings of each row in a data frame. It should use each string once, and ...
43 views

How to list all combination of 2 column matrix [duplicate]

I need to list all combination of matrix with two columns. i.e if I have matrix with x1;y1 and x2;y2 I print on screen X1;y1 X1;y2 X2;y1 X2;y2 EDIT : X: [A, B, C] Y: [W, X, Y, Z] For the ...
30 views

Which recursive function is better to calculate combination? [duplicate]

I wrote two functions to calculate a combination. The first one is only for double, but faster. (+ less precise result.) The second one is close to what combination means. Is there a better approach? ...
37 views

Given a word and a number for each letter of this word, how to create a full tree of every combinations?

Let's say I have the word "stack" and for each of its letters there is a number that will define the number of times the letter has to be repeated. In a JSON file I would have the following: { "s":...
31 views

Excluding possible image locations

I need to place images so they are not on each other. I'm looking at matrix 3x3, so 9 places. Image is horizontal and it's taking 2 places. I tried this way (edited): other_position = [e for e in ...
13 views

Request help on a simple divisibility checker with specific rules

In the program that i want to build , i need to function to check if sum of 3 numbers (provided as list) can be divided by 10 without remainder. Any 3 inside the list can be substituded by a 6 and ...
30 views

VBA - Extract data in certain format

I've been given a task to extract some data counts which aren't in very data analyse friendly formats to start with. Since there are about 100 spreadsheets all of which are identical in format - I've ...
49 views

find all combinations that have the same sum more efficiently

I want to find all combinations of four numbers in the range -n to n which added up to zeros. Is there any efficient algorithms to solve this problems? #include <iostream> using namespace std; ...
44 views

What is the algorithm or pseudocode that can loop through every possible combinations of an array of N dimensions?

I need to generate an array of NxN dimensions where each value are binary with all possible combinations. What is the algorithm or the pseudocode that make it possible? Here some case to understand ...
20 views

Get value for user selected combination, from product combination array

I need to get the EAN13 code for the combination that the user selects on the product page. I generated a PS module and hooked it to hookdisplayProductAdditionalInfo. In the module PHP file, I can ...
33 views

Algorithm to create ordered subarrays from unordered array while maintaining insertion order

I was given an algorithm problem during an interview. I've improved upon it, but I still think that my solution is suboptimal. The problem is, given an unordered array in integers, produce subarrays ...
43 views

R: Find all combinations without replacement of a sparse matrix

I want to find all possible combinations (without replacement) of a big sparse matrix. Every combination can choose at most one time from each row and column. My goal is to find the combination that ...
16 views

Another Combination

Very similar to my last question, now I want only the, "full combination," for a group in order of priority. So, from this source table: +-------+-------+----------+ | GROUP | State | Priority | +---...
50 views

Algorithm to schedule interviews between two sets of people

I have two sets of people - Set A and Set B. Both sets are of the same size, say n. People from Set A need to interview m people from Set B and vice-versa where m < n. You can imagine that it is a ...
37 views

The contenation 2 or more variable of variable variables

i setup 2 set contenation of 3 variable. the first set i get from post. the second set i get from database. the code 1st set \$code = \$_POST['code']; //A0001 \$det1 = \$_POST['det1']; //it something ...
85 views

An algorithm to find all distinct sums from a list of numbers

Sample input: 4 6 4 3 2 2 1 1 First number = A total, T (T < 1000) Second number = Number of numbers, S (S <= 12) Following S numbers = The values of the numbers (each value < 100). (...
38 views

PHP - How to create words by pattern

I need a code where for example the combination is abcdefgh_12, but I don't know that combination. I have only a******_^2 . How to start a code where it can show me all combinations with all letters ...
41 views

How can I create a method of finding the total number of possible combinations using a dynamic format [closed]

I have a randomly generated custom number plate format which is as follows: ISSIIIISS - Where 'I' is an Integer of 0-9 and 'S' is a string of A-Z An example plate would be: 4DE2947BN I am ...
49 views

Combine all possible characters with days of the week

I have to extract all the combinations of the characters "A, B, C, D, E, F, G", and then combine it with the days of the week so that the result is: Monday AB Tuesday AC Wednesday AD Thursday AE ...
166 views

Efficiently generate all possible 4-man team combination which contain specific character(s) out of 130 characters and calculate certain values

I have around 130 characters (as in game characters) loaded in a dictionary in memory which each value containing specific data of a character. How it works? Each character has 2 chats and 22 ...
53 views

Find Subset Combination in an Array

I have difficulties with this particular problem. I was asked to find a combination subsets that have strictly one element less than the input array. For example from array: var num = [1,2,3,4,5] ...
33 views

Create a list with lists of subsets of a given size of set

I need to write a code that gives back the subsets of a given size of a set in a list. So first let's say I want subsets of size 3 from a set (0,1,2,3,4,5,6,7,8) And I want to write out the subsets ...
55 views

Making all combinations of 1 and 0. Code works well in java but not in js

Since the same code is working well in Java, there shouldn't be a logical problem. They are exactly same. Java code: public class ZeroOneGen { public static void ZeroOneGen(int[] dataArr, int ...
92 views

best combination algorithm of complex data with multiple contraints

I guess we can say that this is very similar to an already asked question here (Optimisation/knapsack algorithm with multiple contraints in JavaScript), which hasn't yet an answer. Let say we like ...
38 views

How to find the vector's values (only integers) which satisfies some linear constraints in R?

Given a vector and a sum, for example limits = c(1,2,5,6,7,6) and sum = 10. The given constrains are: x1 <= limits[1] x2 <= limits[2] x3 <= limits[3] x4 <= limits[4] x5 <= limits[5] x6 ...
60 views

How to count unique combinations from a data table in R?

I have a data table with three columns. The first two are a collection of the data points (categorical data that can be either A, B, or C). The third column is a concatenation of the two data points ...
68 views

Number of ways to traverse a N*N matrix using the Permutations and Combinations

The idea is to travel from the top left corner to the bottom right corner of a N*N matrix, where the only movement allowed is either down or to the right. No back tracking allowed. This is simple ...
247 views

Generating All Combinations of List n Levels Deep in Java

I'm using the following code to generate a list of combinations of size s: public static <T extends Comparable<? super T>> List<List<T>> combinations(List<T> items, int ...
246 views

How to generate all possible vectors based on sampling without replacement in R?

I have a pool of seven numbers. I would like to generate all vectors of length 7 with: two first elements are drawn from the pool of the 7 numbers. two next elements are drawn from the 5 numbers left....
87 views

gradually interleave one list with another [duplicate]

i tried to gradually interleave one list with another. i mean: starting from the lists a0 = list(range(3)) # [0, 1, 2] a1 = list(range(10, 13)) # [10, 11, 12] i would like to be able to iterate ...
84 views

Find count of all such distinct tuples, (i, j, k) where (i*j)%k == 0

Given a number n. How to find the count of all such distinct tuples? (i, j, k) where (i*j)%k == 0, where 1<=i<=n, 1<=j<=n, 1<=k<=n in O(n^2) or better.
17 views

Is there a way to create multiple nested loops based on macro and argument?

I'd like to allow for variable numbers of nested loops to iterate through all combinations. I've tried looking at other code samples, but nested loops run FAR faster than anything else I've seen that ...
32 views

How to generate all possible ways of labeling (classifying) a set of objects using a set of labels in python?

Assume that we have a set of objects: set_of_objects = {1, 2, 3, 4, 5} and a set of classes: set_of_classes = {'a', 'b', 'c'} How can we generate all ways of classification of the set of objects ...
40 views

Generating all combinations of a list of strings with both parentheses and an operator being permuted, too

Let's say I have a list of the strings: l = ['A','B','C','D'] I know that to generate all combinations of these with replacement, choose n, that I would use the itertools.combinations library method ...
73 views

Best way to combine a permutation of conditional statements

So, I have a series of actions to perform, based on 4 conditional variables - lets say x,y,z & t. Each of these variables have a possible True or False value. So, that is a total of 16 possible ...
52 views

Find all combinations consisting of one row per multiple arrays

I have multiple two dimensional arrays. I want to find all combinations consisting of one row from each array. Example: Let's say array A has rows a0, a1, a2. Let's say array B has rows b0, b1 The ...
62 views

Finding all combinations of words that form a word

I have a list of words, some words can be formed using two or more other words, I have to return all such combinations. Input : words = ["leetcode","leet","code","le","et","etcode","de","decode","...
34 views

Combinations from a Single Table, Grouped By a Column Value

I have a table of values: +-----+-------+ | ID | STATE | +-----+-------+ | 1 | AL | | 1 | AZ | | 1 | MI | | 2 | TX | | 2 | TN | | 2 | MO | | 2 | ND | And many, ...
21 views

Generate all possible combinations of the elements of n arrays [duplicate]

I try to generate the combinations of the elements of n arrays. This is what I have initially: \$colors = array("red", "blue"); \$flowers = array("rose"); It can become more arrays though. So it ...
53 views

Is there a way to calculate all possible combinations of multiple arrays?

I am trying to find values for four different parameters (kc, tauI, tauC, tauD) in order to optimize the performance of a controller. I want my program to test as many combinations as possible within ...
17 views

Algorithm to find the k sets of values from N sets such that the number of unique values across the k sets is maximised

I have a database of N billboards giving the IDs of all the people that saw each billboard. I need to find the k billboards that have been seen by the largest number of unique people across the k ...
11 views

Is there a Python function to Get frequent itemsets from two DataFrame Parameters?

The following dataframe, I devided its itemsets into two groups and created two dataframes. I want to generate frequent itemsets from two dataframes -without combining them in one dataframe-. This ...
42 views

Combinations of a list of list - Elementwise

I am looking for a method to generate all possible combinations of a list of lists, under the condition that there should only be "elementwise" combinations. Thus, if we have the lists [1,2] and [3,4],...
80 views

Generate lexicographic series efficiently in Python

I want to generate a lexicographic series of numbers such that for each number the sum of digits is a given constant. It is somewhat similar to 'subset sum problem'. For example if I wish to generate ...