Skip to main content
Filter by
Sorted by
Tagged with
-1 votes
1 answer
67 views

Recombining 4 pairs of numbers

I have a question for a personal project of mine, that has stumped me. The goal is to generate all legal combinations of a set of 8 numbers, that split into 4 pairs. For a combination to be considered ...
Mikołaj Gano's user avatar
1 vote
1 answer
122 views

How to recursively calculate all paths to a terminal state in an iterated system with two state variables? [closed]

Compute the number of ways to reach the terminal state (A = 1) using recursion. Consider an iterated system with two state variables A and B. A can have a values of 0 or 1 B can have a value of 0,1,...
Anny Fernando's user avatar
1 vote
0 answers
66 views

Optimizing Column Selection for Row-Wise Minimum Sum in Matrices

I have an issue finding an efficient solution for the following problem: Given a rectangular matrix of integers with dimensions 𝑚×𝑛, select exactly 𝑄 columns and then, for each row in the matrix, ...
Skaral Larax's user avatar
0 votes
0 answers
106 views

Sorting numbers into bins of the same sum

I am trying to find the optimal way to sort a collection of integers into bins that all have the same sum. For simplicity we can subtract the average so we are only interested in bins that add to zero....
Bobby Ocean's user avatar
  • 3,294
5 votes
1 answer
140 views

Algorithm to count permutations with specific fixed points and relative value constraints

I'm trying to optimize an algorithm that counts permutations with specific constraints. Given integers n, t, a, b where: n is the length of permutation (1 to n) t is the required number of fixed ...
Peter Thomas's user avatar
1 vote
3 answers
92 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 ...
user430997's user avatar
0 votes
1 answer
45 views

How to iterate through categorical combinatorics of different Enum classes in Python?

I have a function - main() that takes in an instance of a class InputPermutation as it's only argument. The idea being that differences in the results from a run of the main() are based solely on the ...
k_1223's user avatar
  • 5
1 vote
4 answers
150 views

Generate all possible Boolean cases from n Boolean Values [closed]

If two fields exist, the corresponding fields are Boolean values. x_field(bool value) y_field(bool value) I want to generate all cases that can be represented as a combination of multiple Boolean ...
Antoliny Lee's user avatar
0 votes
1 answer
93 views

How many ways can I choose numbers (repeatable) from a set that amount to the same sum?

For example, I have the following denominations {5, 10, 20, 50} The user input the amount they want to withdraw (e.g. 20), and the code will print out 4 because there are 4 ways to stack these bills ...
Florecita's user avatar
0 votes
1 answer
51 views

Using multi-indexing to find all combinations matching a certain pattern

I need to write an algorithm that takes N points, and outputs all the possible 3-stars and triangles that are formed by the points. Here's an example for clarification. Let N = 4, then I have 4 choose ...
Ollie's user avatar
  • 117
0 votes
2 answers
133 views

Is there a simple and efficient way to evaluate Elementary Symmetric Polynomials in Python? [closed]

I'm currently working on a project that involves evaluating Elementary Symmetric Polynomials (or "ESPs") using Python. So essentially I need to create a function that : takes a non-empty ...
bghost's user avatar
  • 103
0 votes
0 answers
84 views

tuples of integers with fixed sums up to permutations

I'm stuck with the following problem which I need to speed up a piece of code I have written in the past. I am programming in python, but this question is more about the algorithm than about the ...
PRT's user avatar
  • 11
1 vote
0 answers
82 views

Algorithm to Count Permutations Without Adjacent Repeating Characters and Find the Inverse

I would appreciate the help of this great community in finding an algorithm (in any programming language, though I have it in Visual Basic) to solve two related problems: Counting permutations with ...
Mencey's user avatar
  • 69
1 vote
1 answer
97 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 ...
Trailblazer's user avatar
3 votes
2 answers
104 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 ...
snothaft's user avatar
2 votes
1 answer
133 views

Count the number of integers in range [0,k] whose sum of digits equals s

Count the number of integers in range [0,k] whose sum of digits equals s. Since k can be a very large number, the solution should not be O(k). My attempt of a O(s log(k)) solution (log(k) is ...
eigenless's user avatar
0 votes
1 answer
101 views

finding the number of possible k non-attacking rooks in an NxM chessboard with forbidden tiles?

I have an NxM incomplete chessboard (meaning an NxM chessboard with some tiles missing) and a number k (which is the number of non-attacking rooks I need to place on the board) the inputs of this ...
Nate3384's user avatar
  • 143
1 vote
0 answers
33 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 ...
Paolo Molignini's user avatar
1 vote
0 answers
66 views

Linear combinations of special square matrices to receive certain output matrices

The following question is one I asked 3 years ago on MathOverflow: Linear combinations of special matrices Since I am still interested in an answer I would like to post it here too. Before I state the ...
BenBar's user avatar
  • 11
2 votes
1 answer
105 views

Summing Nodes in a Network

I was reading about this over here: https://en.wikipedia.org/wiki/Valeriepieris_circle . This is a problem where the task is to find the smallest possible circle that contains half of the world's ...
farrow90's user avatar
  • 839
0 votes
1 answer
173 views

Count possibilities to reach top of stairs by Taking one, two or three steps at a time

I'm looking at the following challenge: Fibonacci is a young resident of the Italian city of Pisa. He spends a lot of time visiting the Leaning Tower of Pisa, one of the iconic buildings in the city, ...
Soham's user avatar
  • 15
-3 votes
2 answers
237 views

Checking all possible combinations of integers with a fixed sum and size [closed]

I am trying to iterate over all possible combinations of integers with a given sum and size, in order to find the item with the lowest standard deviation. For example, if sum=4 and the size=2 then ...
HDNW's user avatar
  • 115
-1 votes
4 answers
84 views

N choose r possibilities as increasing binary numbers [closed]

I am looking for a function that inputs (n,r) and outputs the all the ways in which we can pick r objects from a string of n objects. Moreover, I would like this list as an increasing, binary sequence....
Ultra's user avatar
  • 109
1 vote
2 answers
91 views

Parse every k-element subset of an n-element vector

My goal is to perform an operation on every k-element subset of n elements stored in a vec. My current approach uses this bit-manipulation to generate integers with k set bits in lexicographic order. ...
Dave's user avatar
  • 9,066
0 votes
0 answers
23 views

I want to obtain a tensor with all possible combination of the rows of a matrix in Torch

I have a tensor of 4 dimensions let#s call them N,T,V,C, now I would like to have a tensor of dimension N,T,C^V, or better N,T,C,C,...,C for V times, where the elements are the outher products of the ...
nicco's user avatar
  • 1
7 votes
0 answers
115 views

Number of partitions of (a,b) into k distinct parts which sum up to (a,b) [closed]

Problem set This is somewhat a generalization of the famous partition of integer n into k parts. Given two integers a,b I need to find the number of partitions into k distinct parts that sum up to (a,...
linuxbeginner's user avatar
3 votes
2 answers
134 views

Get the indices and corresponding combinations that contain given term from a list of combinations with replacement

Let's say I have an ordered list of combinations with replacement with n=4 (objects) and r= 3 (sample): [1, 1, 1] [1, 1, 2] [1, 1, 3] [1, 1, 4] [1, 2, 2] [1, 2, 3] [1, 2, 4] [1, 3, 3] [1, 3, 4]...
ufghd34's user avatar
  • 163
1 vote
1 answer
54 views

Number of routes of Königsberg's Bridges problem in Christopher Moore's "The Nature of Computation" [closed]

This is supposed to be a very simple question. In the Prologue of Christopher Moore's book "The Nature of Computation" (2011), page 3, the number of possible routes of the Königsberg problem ...
FJDU's user avatar
  • 1,473
1 vote
2 answers
79 views

Sampling from a Superexponential Population in Polynomial Time

I'd like to sample from a well-defined population of super-exponential size with uniform probability among the population. For example, say the population is the set of unique permutations of ...
obviouslyalive's user avatar
1 vote
1 answer
110 views

Find the vertices of all the sub-simplexes following Barycentric subdivision

I have a set of K dimension standard basis vectors and the (K-1)-simplex defined over these vectors. I want to divide this simplex into sub-simplexes which partition the original simplex using ...
Joe Emmens's user avatar
1 vote
0 answers
54 views

An optimized alternative to an exhaustive search in terms of time

I have a list of 53 points with associated losses for each, then I generate a list of n-combinations for these. The idea is that, for example, I take 3-combinations of these (53C3) which are around 23,...
PeakyBlinder's user avatar
1 vote
1 answer
176 views

Can I generate a list of sentences from a list of words?

I want to take a group of words, ideally at least 100, and then get sentences that actually make sense. Any grammar check API I've seen can correct sentences if they are in a form that at least ...
user24883689's user avatar
10 votes
6 answers
565 views

Filtering the Results of Expand.Grid

I am trying to generate a list of all combinations numbers that satisfy all the following conditions: Any combination is exactly 6 numbers long The possible numbers are only 1,5,7 1 can only be ...
stats_noob's user avatar
  • 5,877
3 votes
1 answer
78 views

Find nonnegative integer weights of integer inputs array for integer output, minimizing sum of weights

Problem: Given an array of integers inputs and an integer output, return an array of non-negative integers weights such that the sum of the element-wise product of inputs and weights equals output and ...
Gigi Bayte 2's user avatar
5 votes
2 answers
149 views

Generating combinations in pandas dataframe

I have a dataset with ["Uni", 'Region', "Profession", "Level_Edu", 'Financial_Base', 'Learning_Time', 'GENDER'] columns. All values in ["Uni", 'Region', "...
Egor's user avatar
  • 97
2 votes
1 answer
102 views

List all ways to draw n numbers with replacement out of m < n values (i.o.w.: all partitionings of a set of size n into m distinct subsets) in R

In a simulation study, I need to generate all distinct ways to generate a sequence of m numbers between 1 and n (n>m) such that the sum of the numbers is n, i.e. nums <- c(n_1, n_2, ..., n_m) ...
cdalitz's user avatar
  • 1,267
1 vote
1 answer
49 views

Find if a set of lists of 2 values are the result of the possible combination of a n-value list

I have used itertools to find all possible 2-element combination (without repetition) from a set of 10 elements to which I have applied some filtering to reduce the 2-element combination based on ...
Marco_sbt's user avatar
  • 327
1 vote
1 answer
134 views

Go: Iterate all possible combinations of elements in n arbitrary slices

Say we have a struct with n visible fields that are slices of arbitrary types and lengths: var parameters := struct { Parameters1 []int Parameters2 []byte // ... ParametersN [][]byte } { ...
ibarrond's user avatar
  • 7,491
1 vote
4 answers
160 views

Formula for the Nth bit_count (or population count) of size M

I am interested in finding a simple formula for determining the nth time a particular bit_count occurs in the sequence of natural numbers. Specifically, what is the relationship between K and N in the ...
Bobby Ocean's user avatar
  • 3,294
2 votes
2 answers
124 views

How to Enumerate Pandigital Prime Sets

Project Euler problem 118 reads, "Using all of the digits 1 through 9 and concatenating them freely to form decimal integers, different sets can be formed. Interestingly with the set {2,5,47,89,...
Julian's user avatar
  • 23
3 votes
2 answers
76 views

Integers into random order with constraints in R?

I want to sample integers in R, but also set constraints that for example, "3 comes always before 2" and "8 comes always before 5". EDIT: The integers need not to be next to each ...
Aku-Ville Lehtimäki's user avatar
3 votes
2 answers
150 views

Minimum cases of n choose k with respect of n choose q

I have a list people = ['P1', 'P2', 'P3', 'P4', 'P5', 'P6', 'P7'] allComb4 = list(itertools.combinations(people,4)) # n choose k #[('P1', 'P2', 'P3', 'P4'), ('P1', 'P2', 'P3', 'P5'), ('P1', 'P2', 'P3'...
Ciprian's user avatar
  • 209
1 vote
1 answer
102 views

Filter elements in the list A, based on the list B, such that for a in A there exists at least one element b in B, where a = (a&b)

I have 2 lists of ints: A and B. How can I efficiently ensure that for every element in A there exists at least one element in B such that when they are bit-anded, answer is that element in A. Eg. B = ...
Nihar's user avatar
  • 29
1 vote
0 answers
77 views

Is my logic correct? A bit string of n with more 0s than 1s

I am learning about combinatorial and bit strings. I want to solve for a string with unknown length but has 0s than 1s. I decided to use combinatorial reasoning and explain my thinking Is my logic and ...
cool cat's user avatar
0 votes
0 answers
29 views

Giving each student a set of questions so that any two would have minimal number of common questions

I need to create an algorithm that would give a set of questions to each student based on students` majors, number of students, possible questions. I am hosting an exam for my students. Each student ...
berlord's user avatar
  • 11
1 vote
3 answers
115 views

All combinations 1 to n_1, 2 to n_2, ..., n to n_n in R as vectors in a list?

I am looking for the most efficient way to create combinations based on n different series in R. Base R has this nice function called expand.grid which returns all the combinations as a data frame, ...
Aku-Ville Lehtimäki's user avatar
1 vote
1 answer
76 views

Number of the binary strings that have the given number of occurrences [closed]

How many binary strings exists that have exactly five occurrences of "00", three of "10", three of "01" and three of "11" ? I tried to solve it using induction, ...
FrOZEn_FurY's user avatar
2 votes
0 answers
38 views

Seeking Efficient Enumeration Strategies for Graph Partitioning

I am currently working on a class project that involves partitioning a non-directed graph, possibly weighted, into p classes. The objective is to minimize the sum of the weights of the edges between ...
Goliaaath's user avatar
3 votes
1 answer
150 views

How do I select a combination of two variables from a dataframe when each variable value can only be selected once?

I have a data frame similar to TheDF <- data.frame(VarA=rep(c(7, 8, 11, 14), 4), Var2=c(1,1,1,0, 0,2,2,0, 0,0,3,0, 0,0,4,4), Var3=c(50, 50, 50, 50, 100, 100, 100, 100, 150, 150, ...
Michelle's user avatar
  • 1,363
1 vote
1 answer
56 views

R: Creating all possible between group combinations without within group combinations

I have a vector like this: v <- c("v1" = 3, "v2" = 1, "v3" = 2, "v4" = 1, "v5" = 2, "v6" = 4, "v7" = 1, "v8" = ...
Laas's user avatar
  • 37

1
2 3 4 5
48