As of May 31, 2023, we have updated our Code of Conduct.

Questions tagged [combinations]

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

Filter by
Sorted by
Tagged with
-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 ...
Vudo's user avatar
  • 1
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 ...
ViridTomb's user avatar
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 &...
Neil Peña Martínez's user avatar
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 ...
Stgauss's user avatar
  • 57
-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 "...
Szyszka947's user avatar
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 ...
Random Actions's user avatar
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,...
Varun Sharma's user avatar
  • 2,541
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 ...
Adithya's user avatar
  • 189
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 ...
kksimons's user avatar
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 ...
aksent1344's user avatar
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 ...
UnderscorePoY's user avatar
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 ... ...
JimboAsks's user avatar
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 ...
Jim Burke's user avatar
  • 217
-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 ...
FN_'s user avatar
  • 712
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 ...
Job Brüggen's user avatar
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 ...
Kevin's user avatar
  • 47
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 ─────┼────...
JeanJouX's user avatar
  • 2,555
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 ...
Benjamin Thuret's user avatar
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 ...
ermal kopliku's user avatar
-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','...
joelatina's user avatar
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",&...
Nicholas's user avatar
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)). ...
никита тюленев's user avatar
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(...
user472543984's user avatar
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 ...
user1415785's user avatar
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 ...
Lilia's user avatar
  • 109
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 ...
Taha Smoke's user avatar
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....
Anshuman Acharya's user avatar
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,...
user2109046's user avatar
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 ...
MJA's user avatar
  • 1
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;...
Dnjl_01's user avatar
  • 27
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), (...
Eric's user avatar
  • 21.7k
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, ...
Plant's user avatar
  • 1
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 ...
hundreAd's user avatar
  • 158
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 ...
Ross's user avatar
  • 1
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 ...
jonas87's user avatar
  • 672
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);} ...
A. T's user avatar
  • 1,686
-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 ...
willem12's user avatar
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 ...
mattdonders's user avatar
  • 1,318
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 ...
janosch's user avatar
  • 23
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", &...
pemb_bex6789's user avatar
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 ...
Bryce Towle's user avatar
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....
Mailinnia's user avatar
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(&...
Jirka Čep's user avatar
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 ...
yenaibangbing's user avatar
-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-...
Lazy Titanic's user avatar
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 = ...
user113156's user avatar
  • 6,657
-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 ...
Joe Nibali's user avatar
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 ...
Guh Bolinha's user avatar
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 ...
bipbipbip's user avatar
-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 ...
Believe82's user avatar

1
2 3 4 5
126