Questions tagged [combinations]
A combination is a selection of objects from a larger collection in no particular order.
6,277
questions
-2
votes
1
answer
18
views
What is the smartest way to solve CSES - Dice Combinations in python? [closed]
I know it can be solved using Dynamic Programming but I don't know the way to solve the problem. Can someone explain step-by-step the way to solve it in python or just the way to solve without code to ...
0
votes
0
answers
33
views
Partition list of numbers into groups that sum to specific sums
I have a list of sums such as [7,6] and a list of numbers that will sum to the list of sums. For instance, [4,3,2,2,2]. Numbers in each list could be randomized. The goal is to return a result array ...
1
vote
1
answer
41
views
Calculating currency combinations efficiently
In the game Team Fortress 2, weapon, metal, and keys are used as currencies. Metal is subdivided into three types: scrap, reclaimed, and refined (from now on "scrap", "rec" and &...
0
votes
1
answer
17
views
Flatten output list from sympy
I'm calculating a whole bunch of scenarios, involving the geometry of a floor slab. Pretty much what I need to do is iterate every single case for lengths up to 200 meters, and thicknesses up to 120 ...
-1
votes
1
answer
70
views
Generate all possible combinations basing on binary string and under some conditions
I have to write algorithm that will generate all possible combinations of different binary strings but under some conditions. The combinations are created by:
Replacing binary "1" with "...
2
votes
2
answers
33
views
Algorithm to list all combinations from a table where data is present or NULL
I have an Excel file (which can optionally be loaded into a database, and into an array of arrays of course) with values such as:
A
B
C
NULL
NULL
zxy
xyz
xzy
NULL
xyz
xzy
xyy
yzy
yyx
yxy
NULL
...
0
votes
2
answers
62
views
Generate combinations by combining adjacent characters
I have a program that should generate combinations of concatenation of all possible adjacent characters.
For example
Input = [a,b,c]
Output = [a,b,c], [ab,c], [a,bc]
Input = [a,b,c,d]
Output = [a,b,c,...
7
votes
3
answers
493
views
Numbers of combinations modulo m, efficiently
First of all I'm solving a programming problem rather than a math problem now.
The question is
Anish got an unbiased coin and he tossed it n times and he asked Gourabh to count all the number of ...
0
votes
0
answers
40
views
How can I efficiently generate and compare all possible class schedule combinations using Python?
I'm trying to build a simple python that finds the optimal schedule based on a provided class schedule dataset.
The idea was for the program to parse the dataset, come up with all the possible ...
1
vote
2
answers
24
views
Count product combinations which are under same customer
I have table like this:
Customer_nr
Product
11111
Table
22222
Sofa
333333
Table
444444
Closet
11111
Bed
How can I find the number of product combination that a bought by same customer?
Out come ...
2
votes
1
answer
62
views
Why isn't Python itertools.combinations() in O(1) amortized time complexity?
The itertools.combinations function of the CPython's standard library doesn't have an $O(1)$ amortized time complexity. When generating $k$-combinations of $n$ elements, the main issue arises from ...
1
vote
2
answers
55
views
Algorithm that gives a certain permutation of letters from an input value
I'm looking for a function that takes a certain input value and transforms it into a certain sequence of letters using the full alphabet.
This is the exact input: output I need:
5: aa
6: ab
7: ac
...
...
3
votes
1
answer
58
views
Find all numbers in a set of maxima that sum to a given number
I am struggling to think of an algorithm which matches my needs. I have a list of integers in a set, each integer represents a maximum value, the list can contain >= 1 entries. I would like to ...
-1
votes
0
answers
27
views
How to generate variable combinations without getting error "too many statically nested blocks"
the question
Hi, I have an app, that has 30 inputs (and the number is increasing in time). Base on the input, the output changes. I need to test several combinations per each input. Right now, I am ...
0
votes
1
answer
34
views
Iterating over Dataframes - revisited?
I have a dataframe of about 500.000 rows. Contains long, lat,, altitude, datetime (and a LOT more data) of aircraft radar data.
To calculate 'propensity' (a dimensionsless number based on closest ...
1
vote
1
answer
53
views
Perform Action to all possible combinations of columns
I´m new to R so forgive me if the question is quite mundane.
I have a table with categorical variables as columns. I need to calculate the contingency coefficient between every possible combination of ...
1
vote
1
answer
17
views
Share out a value on multiple entries with DataFrames in Julia
I'm new with the Julia programming language and I would like to group scores by country in a DataFrame like :
Row │ Name Score Country
│ String15 Float64 String15
─────┼────...
2
votes
2
answers
141
views
Choose 14 combinations from 100 including all the numbers found in the list, and taking into account their frequency of appearance
I can't finish this script. Could you help me?
Either a list of 100 combinations composed of 5 numbers ranging from 1 to 49. The purpose of this script is to choose 14 of these combinations in an ...
0
votes
0
answers
16
views
Create a list of non-overlaping segments
I'm new to Python and I want to find an elegant solution to this problem:
I have a set of interesting segments defined by three attributes (bottom, top, value).
I want to create all possible ...
-1
votes
1
answer
38
views
Writing combinations from a list of strings where output is longer than input
What I'm trying to do is to take a list like this:
['WS','SB'...]
And write a python program that will produce an output like this for each string in the list:
['WWWW','WWWS','WWSS','WSSS','SSSS','...
2
votes
1
answer
71
views
How to get all possible combinations of a vector in R with all possible arithmetic functions?
I would like to do a permutation of variables with all arithmetic functions in R.
example:
testvector <- c("cat", "dog")
# expected outcome
c("cat","dog",&...
0
votes
1
answer
57
views
Euler function of C(n, k)
Strange combination I know but here is my question:
We have 0 <= k <= n < 500000.
We need create an anlogithm that calculute Euler function of C(n, k) and not spend all your life for it)). ...
1
vote
2
answers
39
views
All possible pairs of each list within a list
I have the following code as an example (this is based on pairwise similarity of textual definitions):
import pandas as pd
df = pd.read_csv("pairings.csv")
sample_list = df['fruit'].tolist(...
0
votes
0
answers
25
views
Generate magazine flatplan with constraints
I'm working on a magazine. We are working with multiple types of papers (short articles, long articles, portfolio, ads, etc.) that together make 128 pages in total. I'm looking for a way to generate ...
1
vote
1
answer
30
views
Replace with zeros columns using all combinations in matlab
I'm trying to loop through all the combinations of columns replacing with zeros.
My code replaces one column of zeros each time, i.e nchoosek(5, 1) and I generated nchoosek(5, 5) but I need the rest ...
0
votes
0
answers
11
views
Wires combination configurations
I need to create macro Excel generating all possible combinations of wires.
I have the following list of wires each one is called by its options (OP1, OP2,...)
enter image description here
the options ...
0
votes
2
answers
47
views
Pick some combinations of r elements out of all possible combinations of elements from an array of length n
So I have a list of lists, say superlist = [sublist1, sublist2, ...,sublistn] of length n.
I need to randomly pick a large number of combinations of r elements from it, but not necessarily all of them....
0
votes
1
answer
66
views
Combinations Optimization in Python
I'm planning a golf trip with 6 people, trying to optimize the pairings. I start with the number of combinations and then randomly sample for 5 rounds. My goal is to create the cross matrix of row[a,b,...
0
votes
0
answers
8
views
SAS - compare two datasets by 1 to 5 non-unique key variables to flag missings and differences?
I am looking to compare two SAS datasets. They can be compared by up to 5 'key' variables which are sometimes not unique. If I were to do this by several separate merges this would be
merge by VarA
...
0
votes
0
answers
37
views
Count individual combination of two variables between two columns
I want to count the individual combination of two variables between two columns, for making a barplot or pie chart afterwards.
Here the example:
dat <- read.csv2(file = textConnection("a;b
x;...
2
votes
3
answers
151
views
No general solution to k-combination of multiset?
The problem to solve
Solve k-combination whose input may contain repeated items, and return only unique combinations.
e.g input is [0,1,2,2,4], k = 2, the result is:
{(0, 1), (2, 4), (1, 2), (0, 4), (...
0
votes
2
answers
36
views
Search through two different dataframes and merge them
I have the two following dataframes. The combination of type, P_val and C_val is always unique and C_PP_val in df1 refers to C_val in df2. I am trying to merge these two dataframes based on type, ...
0
votes
4
answers
152
views
Algorithm to loop over all item combinations, where some are deleted during the process?
I am looking for a good algorithm/data structure to do the following:
Loop over all item combinations:
For example, for A, B, C, D, E:
AB, AC, AD, AE
BC, BD, BE
CD, CE
DE
(Symmetrical i.e., AB and BA ...
0
votes
0
answers
53
views
Excel formula to make Combinations using =MAKEARRAY
I want to use the forumla =makearray() to create an array of all possible combinations of numbers.
Variables are N,R
Population would be {1,2,3,..N-1,N}
Set would be {1,2,3...R-1,R}
Number of Array ...
8
votes
1
answer
362
views
Find all possible sums of the combinations of sets of integers, efficiently
I have an algorithm that finds the set of all unique sums of the combinations of k tuples drawn with replacement from of a list of tuples. Each tuple contains n positive integers, the order of these ...
0
votes
1
answer
49
views
Error in the code ( k element out n ) in julia and Singular
I am trying to write my own code for Singular language and I am getting errors.
the question is repeated [here][1].
proc combination(int n, int t)
{
list s;
if( t == 0)
{return (1);}
...
-1
votes
1
answer
53
views
Mapping four string values to all different possibilities of two number ranges in a nested dictionary in python
I have the following lists. In reality these lists are a lot bigger but I simplified for the example.
d = ["a", "b", "c", "d"]
p = [1,2,3,4]
a = [1,2,3,4]
I ...
0
votes
1
answer
37
views
Get All Combinations of N-Length For Different Sized Input Lists
I have seen other questions on using itertools to generate combinations from a single list & even a list of lists, but I am looking for something slightly different.
I have a list of lists of ...
2
votes
2
answers
54
views
Expand dataframe by unique combinations and calculate their means
I'm trying to append rows to an dataset with combinations of the existing classes. I then want to calculate the means of the unique class combinations. It is similar to a pairwise post-hoc test but I ...
0
votes
0
answers
24
views
How do I get all pairs of combinations from a list of variables including duplicates and self combinations (for correlation)?
I can see from the link below how to get a list of unique combinations and then how to combine this with self combinations
Non-redundant version of expand.grid
e.g.
factors <- c("a", &...
0
votes
1
answer
60
views
Is there a way to show all possible combinations of the values 0-4 for 5 values?
I am trying to help develop a grading scale which determines the overall grade for a student with 5 assignments entered in A (4) to F (0) with no plusses or minuses. I would like to see each possible ...
0
votes
2
answers
51
views
Python find all non-repeat combinations and get both the values they have in common and their unique values
I have an array of sets [setA, setB, setC, setD, ..., setX] and I want to find a way to get the intersection of each combination (without repeat combos), so:
AB = setA.intersect(setB)
AC = setA....
3
votes
3
answers
71
views
Get all level combinations for each group
I have a list of customer IDs, each with a list of unique products they used. There can theoretically be up to ~150 unique products.
df <- tibble(ID = c(1,1,1,2,2,3,3,4),
prod = c(&...
0
votes
1
answer
121
views
An algorithm problem about output all subset of all n numbers [duplicate]
Now I'm researching about communications of n cars, the problem I meet can be simplified as:
n numbers, and I want to get all the subsets, which meet the condition that they are divided (like the ...
-1
votes
2
answers
64
views
Efficient sums of n-length combinations of array
Given the following input:
An integer n, e.g., 36.
An list/array mylist of length m, e.g., [0.0, 24.0, 48.0, 72.0, 96.0, 120.0]. Although the values in this example are evenly spaced and integer-...
1
vote
2
answers
52
views
Get all combinations of character string of length N [duplicate]
I have the following data:
fruits <- c(
"apples and oranges and pears and bananas",
"pineapples and mangos and guavas"
)
str_split(fruits, " and ", simplify = ...
-1
votes
2
answers
159
views
C++ program that calculates all possibilities of a sum with given numbers (duplicates allowed)
I need to write a program in C++ that takes a set amount of numbers (specifically 1 and 2) and then calculates how many combinations these numbers can forum a total sum.
For example if the total sum ...
2
votes
1
answer
48
views
Calculate combination index
I'm trying to find a algorithm/base snippet (if that's even possible) to calculate the position of a combination of values - in order not to store all possible combinations.
It could be some simple or ...
0
votes
1
answer
37
views
Want org data totals by date for multiple dates in a single results table from a query on a transactions table
The problem, near as I can explain it, is I can't figure out how to feed dates into another query one by one to produce results in a single table. I'm trying to treat a query that creates totals like ...
-1
votes
2
answers
42
views
Python separating the result of combinations
I have the following code I took from Geeksforgeeks.org to obtain combinations of a list:
from itertools import combinations
def comb(lper,n):
# A Python program to print all
# combinations of given ...