6,457 questions
0
votes
1
answer
161
views
Advanced combinatorics in Python: binom(n,2) subsets of binom(n,3) combinations without repetition
I have a list d_n of n integers and the results Z_klm of a function fun(dk, dl, dm) for all binom(n, 3) combinations without repetition (k, l, m) out of d_n indices.
Now, for all binom(n, 2) ...
8
votes
3
answers
1k
views
How can I create an array of arrays of strings of varying lengths in C?
I am trying to solve the problem posed in this question. Here the OP asks that given a 15 element set, its 2^15 element power set be generated in a manner such that the elements of the power set are ...
2
votes
1
answer
199
views
How to compare a reference combination to multiple cells and return the closest match header in Excel? [duplicate]
I'm working on an Excel sheet where I have:
A reference combination in cell S4, like 4,D,D,D,D,D,D,D
A range of combinations in W3:AH6, where each cell contains a comma-separated string like 3,A,A,A,...
4
votes
2
answers
190
views
Combination generator written in C : works for big n but for small n when n=0 or n=k crashes saying "segmentation fault"
Let's say I have a box and there is a bunch of balls in that box. I can label each ball with a character while making sure no two balls get the same character as labels. I get a string this way. Let's ...
-1
votes
3
answers
359
views
Creating all possible combinations of N items in a list?
I'm working on generating all possible combinations from a list of N elements, regardless of the number of elements in the resultant combinations. This is basically the power set without the empty ...
1
vote
2
answers
122
views
Generating all length-N combinations of all length-M sublists of a list, without repetitions
I have a long input list, and I want to generate combinations of 3 elements. But each combination's elements should be drawn from a length-5 sublist of the original list, rather than drawing elements ...
-1
votes
1
answer
200
views
method to count n-digit numbers that meet given digit patterns
What is a scalable way to count the number of n-digit numbers (in mixed radix) that meet a list of different digit criteria? For example, what are the 4 digit numbers that have any of these patterns ...
0
votes
1
answer
65
views
Generation of particular combinations
In Mathematica I implemented this simple code:
n = 8;
a0 = Range[0, n - 1];
a1 = Subsets[a0, {2}];
a2 = Subsets[a1, {2}];
a3 = Select[a2, Length[Union[Flatten[#]]] == 4 &];
a4 = Subsets[a3, {n/4}];...
3
votes
1
answer
121
views
Target sum algorithm using Numpy
I have a numpy array of floats and a target sum. I am trying to find all possible combinations of elements that would add up to the target sum.
I am struggling to come up with anything computationally ...
0
votes
1
answer
67
views
I have a column in excel and I want to get all sets of combinations in another row or column
Here is my column
enter image description here
I am looking for a formula to get all combinations separated by "/"
Example:
SE/XE
SE/SX
SE/EX
XE/EX
SE/XE/EX and so on
I have so far been able ...
2
votes
1
answer
191
views
How to create possible sets of n numbers from m-sized prime number list?
Input: a list of m prime numbers (with possible repetition), and integers n and t.
Output: all sets of n numbers, where each set is formed by partitioning the input into n parts, and taking the ...
5
votes
3
answers
203
views
Summing columns of Pandas dataframe in a systematic way
I have a pandas dataframe which looks like this:
1_2 1_3 1_4 2_3 2_4 3_4
1 5 2 8 2 2
4 3 4 5 8 5
8 8 8 9 3 3
4 3 4 4 8 3
8 0 7 4 2 2
where the ...
1
vote
1
answer
140
views
What function should I use to sort each row by its columns in a 2d array?
The formula below produces permutations of the digits in the array cols - in this case 1 to 6. The perms variable outputs a 2d array of the permutations without repetitions.
However, I want to get ...
3
votes
2
answers
149
views
Check if a target sum is possible given a vector of values
The problem is to check if it is possible to get a given targetSum from the elements of a given array. Each element should be included once only (if included).
The code is a brute force approach using ...
1
vote
0
answers
75
views
How do I use a custom mapping (sort) on my itertools for loop so that I can print specific strings first?
I'm using python itertools specifically to generate combinations of integer strings. I have already created the loop that will loop through the combinations one at a time. I just need someone to help ...
-1
votes
2
answers
92
views
Find combinations of 2 numbers in a list that those 2 numbers are not the same (Python)
Find combinations of 2 different numbers in a list (In python)
Input:
1st line: n (length of array)
2nd line: array (the array) ex:(1 7 1)
Output:
Numbers of combinations of 2 numbers in a list ...
0
votes
0
answers
43
views
I Need Values from a 2D Array Combined in a Certain Way [duplicate]
I have an array like this:
matrix = [
['A', 'B', 'C'],
['D'],
['E', 'F'],
['G', 'H']
]
And I need to choose a value from each row in such a way as to get this output
ADEG,
ADEH,
ADFG,
ADFH,
...
0
votes
2
answers
176
views
Calculate combinations for a range of text values in excel
I do not know enough about M in PowerQuery to work out how to solve the below.
The example is, I have an excel range of over 300 rows, each with 12 columns that may contain strings of meta-data (these ...
1
vote
1
answer
109
views
Using one dataframe to find matching combinations in fixed sets
A
B
C
D
E
Key 1
1
-1
Key 2
1
-1
Key 3
1
-1
Key 4
-1
1
Key 5
1
-1
Key 6
1
-1
Key 7
1
-1
Key 8
1
-2
1
Final Result
A
B
C
D
E
1
-1
suppose we have the above dataframe where each key is an option ...
0
votes
1
answer
169
views
max combination for a given list
I need an assistant with implementing the following question in Python;
There is a given list:nums = [1, 1, 4, 2, 3, 3, 2, 5]
The request is to write a Python code which gets the maximum number of ...
1
vote
3
answers
85
views
How can I count combinations of variables in R?
I'm trying to count the number of occurrences of combinations across two variables in a data frame in R.
If I have the following dataframe:
df <- data.frame(v1 = c("A", "A", &...
-2
votes
2
answers
80
views
Python itertools product aborting
When running the code below, python aborts and closes the python prompt:
>>> import itertools
>>> nComb = 2
>>> t = range(nComb)
>>> combs = list(itertools.product(...
0
votes
1
answer
119
views
Determining a combination of selections from a list of sets that would yield the maximum number of unique numbers
Determining a combination of selections from a list of sets that would yield the maximum number of unique numbers
Consider an array of sets, with each set containing an arbitrary number of integers.
A ...
3
votes
6
answers
172
views
How do I find all combinations of pairs, such that no elements of the combination have a common first or last value?
I have a list of number-letter pairs like:
all_edges_array = [
[1,'a'],[1,'b'],[1,'c'],
[2,'c'],[2,'d'],
[3,'b'],[3,'c']
]
...
0
votes
2
answers
94
views
From multiple dictionaries, generate all combinations of keys while summing their values
Let's say I have n dictionaries of different sizes, dictA, ..., dictN (n may be as great as 18). They all have strings as their keys and positive numbers as their values. What I need is a dictionary ...
1
vote
3
answers
115
views
Manually calculate all coin flip probabilities from real data
I have this coin flip data:
library(dplyr)
library(knitr)
library(kableExtra)
set.seed(123)
n_flips <- 100
flips <- sample(c("H", "T"), n_flips, replace = TRUE)
I manually ...
1
vote
1
answer
78
views
Fastest way to divide a 2D array in python into counterclockwise patches
Given a 2D array of size (W,H), for example (3,4). You can think of each point in that 2D array as a corner of a rectangular patch. I want to divide that array up into its individual patches as shown ...
1
vote
3
answers
154
views
pivot_wider in R, pivot all combinations [closed]
I have this data. Lots of people share the same id, but have different details about themselves recorded (name and month are often different).
data.frame(
id = c("a", "a", "...
4
votes
1
answer
69
views
Fastest way to combine image patches given as 4D array in python
Given a 4D array of size (N,W,H,3), where N is the number of patches, W,H are the width and height of an image patch and 3 is the number of color channels. Assume that these patches were generated by ...
1
vote
2
answers
72
views
All possible combinations in spatial rectangles coordinates to define rectangle vertex
Due to a memory problem I have decided to download information from EMODnetWCS by rectangles and then merge them.
library(EMODnetWCS)
### Script for downloading information from https://github.com/...
-1
votes
1
answer
190
views
Unable to generate the combination x and combination y using python
Unable to generate desired combination 2 and combination 5
Current OutPut
Combination 1: Rutgers (93), Baylor (93), Orlando (96), Dublin (96), Spokane (96)
Combination 2: Rutgers (89), Baylor (90), ...
0
votes
0
answers
82
views
parallelize double for loop construct for combinations w/o replacement
Unfortunately this is my first openmp attempt. I have a very rough code, that started out as a proof of concept attempt and has yet to be polished (with 50 grit).
I have a container of items and ...
0
votes
1
answer
70
views
How do I use a custom random order on my formula to get the index of a string from the order
I have a script in python that allows me to get the index that a string is on based on the order of the iterables. It's a short script so I want to be able to use a custom order like a completely ...
-1
votes
1
answer
1k
views
How to add a Discount input in Cart page on Shopify (Allow for Discount combinations)
By default, there is no discount input field on the cart page.
I attempted to add a custom input form with the action set to "/discount/YOUR_CODE". However, when I try to apply two different ...
1
vote
1
answer
121
views
Is there an iterator in Python that gives the product but omits permutations of the classes itself?
Assume that I want to assign a color to 5 different balls and have 3 colors r,b and g. I would like to iterate over all these combinations. Preferably I would want to omit combinations that are equal ...
3
votes
2
answers
132
views
Create all Combination from a vector with repeating elements - R
I would like to know if there is a simple solution to finding all combination of a vector with repeating elements. The practical application is in combinatorics math. For example:
There is an urn with ...
2
votes
2
answers
195
views
How to find the combination of numbers that sum (or closer) to a given target?
My input is a list of dicts that correspond to tasks :
tasks = [
{'ID': 'ID_001', 'VOLUME': 50, 'STATUS': 'ENDED_OK'},
{'ID': 'ID_002', 'VOLUME': 10, 'STATUS': 'WAITING'},
{'ID': 'ID_003',...
-1
votes
4
answers
186
views
Split Java BigDecimal into smaller BigDecimal adding up the original value
Is there a way or apache utils function to split a BigDecimal number into random n smaller BigDecimals. I am looking to have this function for creating test data various combinations for a provided ...
0
votes
2
answers
89
views
Add text to combinations and permutations
I am new at codding.I have a question.How do I add text to combinations and permutations I've created? Also, is there a way to delete repetitive states in a repetitive permutation, that is, to print ...
1
vote
0
answers
65
views
Ranking/unranking A-restricted compositions
This might be quite a challenging question, so any help is a appreciated.
I want to enumerate in a sensible way all bosonic states of n=1,2,...,N particles in L sites with maximal occupation per site ...
0
votes
1
answer
56
views
Listing all sets of 5 teams that has one element of each rank
This will be used for a fairly-ranked team-picking (each team must have exactly one element of each rank). One example of elegibe players would be:
Rank 1:'Liam', 'Emma', 'Noah', 'Olivia', 'Ava'
Rank ...
0
votes
1
answer
92
views
How do I get unique pairs based on shared values in two grouping variables?
I have used Florian's answer to this question to get the unique pairs separately for the one shared (grouping) variable. Can this be extended to the case where there are two grouping variables, and ...
1
vote
0
answers
63
views
Generate stable combinations of an unsorted list in python
I have a list made of strings which are not in sorted order. I wish to generate combinations but in such a way that the order of the elements is as in the list. However, Python documentation and its ...
4
votes
1
answer
91
views
How to vectorize groupby combination lists of two columns in Pandas Dataframe
I've a dataframe and need to group by two columns from all possible combinations of dataframe columns ['A','B','C','D','E','F','G']
import pandas as pd
d = {'A': [0,1,1,0,0,1,0,0],
'B': [1,1,0,0,...
0
votes
4
answers
90
views
N series of integers, each of different size, get cartesian product [duplicate]
I have something like this:
{'event1': [2000, 3000, 4000], 'event2': [123, 456]}
but with N keys, not only two like the example
I need to get something like this:
[
{'event1': 2000, 'event2': 123},
{'...
0
votes
3
answers
141
views
Create a list of pairs, by position, from multiple other lists
I need to make a list of pairs from several other lists. The pairs will consist of a value from the same position in each list. There could be a varying number of lists, but each list will have the ...
1
vote
1
answer
82
views
How to resolve complex boolean expressions into all possible combinations
I'm trying to solve the following problem. I have a set of logical operations and I would like to resolve them into all possible combinations. For example:
"((A | X) & B & C) | (C | E) &...
0
votes
2
answers
105
views
Issue in backtracking while creating combinations of a list of size k
def combination(n,k):
combi=[]
def backtrack(start,comb):
print(comb)
if len(comb)==k:
combi.append(comb.copy())
return
for ...
-2
votes
1
answer
76
views
Creating Internal Loops Dynamically
My code is working perfectly :
const i=['a','e','i','o','u'];
let q=[];
for(let t=0,l=i.length;t<l;++t)
{
for(let e=t+1,l=i.length;e<l;++e)
{
for(let z=e+1,l=i.length;z<l;++z)...
3
votes
1
answer
112
views
Iterate over indices in multinomial expansion
Context: In the multinomial expansion, the valid indices [k1, k2, ... kr] for each term fulfill the equation n = k1 + k2 + ... + kr. Given r and n, I'm trying to iterate over all terms. For that, I ...