# Questions tagged [combinatorics]

Combinatorics is the branch of computer science and math that focuses on the enumerable arrangements of a finite set. This includes permutations, combinations, and partitions.

40 questions
Filter by
Sorted by
Tagged with
104 views

### Eliminating combinations based on user input

I am stuck with this particular problem. To give context to the problem, I am developing a mobile app which helps with loading dangerous goods onto a truck. Ignore the size and weight of the dangerous ...
1 vote
74 views

### Algorithm for multi-dimensional maximisation

I would like to devise an algorithm that given: An array of dishes with macronutrient information (proteins, fats and carbohydrates, in grams), constrained to a maximum of around 200 items. A desired ...
• 119
1 vote
122 views

### How to find all combinations of all items in a set? [closed]

Let's say, there's a Product data-model. Product has the attribute - colour, which can, in this case, be red, black, yellow, white, orange. And which in total amounts to 5 different Products. Now I ...
1 vote
223 views

### Software-design for algorithm engineering

I'm currently working on an program that solves a graph optimization problem. I know the "standard" software-design principles like information hiding, modularization, etc. What I'm ...
• 151
1k views

### Time efficient way to count pairs in an array whose sum is divisible by a specific number?

Given an array of integers, we want to find how many explicit pairs can be made such that their sum is divisible by 60. The pairs are not necessarily non-unique. For example, let's say the input into ...
• 1,349
1 vote
184 views

### How to model combinatorial information in RDBMS

I need to model the persistence of combinatorial information. For example, suppose that the combination of 3 attributes (A, B, and C) are used to reference a given product. Besides that, supposed that ...
309 views

### How to generate "meaningful combinations" from the set of characters?

There is a set of feasible characters, say ABCDEF. Combining some of them, I can generate some "meaningful" combinations, say CAFE. I want to gather all of them. To do that, I can just "walk through" ...
• 149
508 views

### Birthday Paradox, Analytical and Monte Carlo solutions give two systemically slightly different results [closed]

I was doing a Monte Carlo implementation of the Birthday Paradox in Python and I wanted to check if the results where the same as in the analytical implementation of the same problem (As they should ...
280 views

### Generating all possible permutations in the fox, goose and beans problem

I have learned graph theory, and am using it to solve the classic Fox, goose and bag of beans puzzle. If we consider that there are three locations for each of the fox (X), goose (G), farmer (F) and ...
• 205
230 views

### Designing a builder as a compile-time state machine

I'm working on a text GUI library which comes with builders for UI components (Buttons, Panels, etc). I have a base class for these builders which I'd like to redesign so that meaningless component ...
• 1,180
120 views

### Generating combinations without getting stuck in recursive calls

This question is about figuring the design of a recursive function that changes the state of a group of elements by processing one of them at a time, with the goal of reaching a desired state. The ...
• 2,126
288 views

### Calendar scheduling: home field constraints

I am working on a round-robin scheduling algorithm for sports. The goal of the algorithm is to schedule all given games across different weeks, in the given fields and given game times. These are ...
• 2,126
180 views

### Calendar scheduling: wait time between games

I am working on a sports scheduling algorithm with several different constraints, one (two) of them being a minimum and/or maximum wait time between games. Of the same team, that is. So if Team Blue ...
• 2,126
1 vote
154 views

### Determining resource exhaustion beforehand

I guess this is a problem solving question but I am out of ideas, don't really know where else I can resort for help, and I need to solve this problem. Essentially we have a set of consumers and a ...
• 2,126
84 views

### Set of items closest to the mean? [closed]

Given a set of N objects with assigned weights, how would we find the set of K objects that is closest to the average? The average being sum(weights) / N. Also, how could we compute the next set ...
• 89
91 views

### How to calculate binomial coefficient C(n, r) modulo some prime power?

How to calculate C(n, r) modulo m, m is of the form p^a, where p is prime. Here C(n, r) means n choose r. The range of n and r is large (of the order of 10^18) so it cannot be solved by calculating ...
310 views

### Permutations for time in JSON

Let's say that I have a JSON file like at example below. How would I go about finding all possible values of item combination time sums that exist between let's say 00:03:04 to 00:25:55 without ...
1 vote
192 views

### How to build an optimal tree given items costs and edge costs?

Given: a list of 'leaves' that each have a cost, the cost of creating an 'edge' The constraint that a constructed tree node can at most have two children. We now want to find the tree with the ...
• 4,479
4k views

### Scheduling: balanced home/away round-robin tournament algorithm

I am trying to achieve a round-robin algorithm for sports scheduling that also guarantees a fair or balanced home/away rotation. I based my algorithm on the round-robin scheduling algorithm: def ...
• 2,126
278 views

### Spreading objects in bags and bags' compartments

We have 10 bags. Each bag has 5 compartments numbered from 1 to 5. We have 100 objects to fill all the compartments and bags. Compartment number x in a bag is identical to compartment of the same ...
• 177
546 views

### Duval's algorithm, Lyndon words and de Bruijn sequence

First, I am not a programmer (yet) and I can only understand basic algorithms written in pseudocode (+Dijkstra, which is a little harder than others, for me). I have been trough logic, set theory, ...
875 views

### How do I write an algorithm to solve a set of 3 symbolic equations

Replace each symbol (letter) with a number so that the equations hold across all 3 equations. Solution should be able to solve the general case of any 3 equations. Can assume 2 terms summed to an ...
• 679
82 views

### Why isn't this combinatorial solution equivalent to the recursive solution for finding the number of "paths"?

Here's the problem: Given an m x n array, get the number of different paths from the top left corner to the bottom right corner, if you can only move down, right, and diagonally down & right. ...
• 105
378 views

### Picking the most calorie-even arrangement of meals

Suppose I eat five meals a day, and since there are seven days in a week, I have recipes for seven of each meal, for 35 recipes in total. Each recipe has a calorie count. Each day must contain one ...
• 99
148 views

### Validating combinations based on rule sets (or similar mechanism)

Let's say I've got many functions and each function accepts an unordered list (order does not matter). For each function I want to see if this list is valid based on certain rules (a knowledgebase ...
• 11
143 views

### Combinations of a password

I am trying to encrypt a password for my school project. Here is the process: Let's assume that I have a string p (n characters long) which contains the password. The program reverses the string and ...
1 vote
433 views

### Why does the last phase of Irving's Stable Roommates Matching work

Pertaining to the Stable Roommates Problem and the algorithm developed by Robert W. Irving. There are two (sometimes broken into three) phases in which we may come to a stable pairing of everyone in ...
944 views

### The maximum number of induced cycle in a simple directed graph

Given a simple directed graph G=(V,E) an induced cycle is a cycle where no two vertices of the cycle have an edge that is not in the cycle. (Chordless cycles are induced cycles with at lease 4 ...
• 101
1 vote
985 views

### Algorithm to create all unique sets of the alphabet using arbitrary group sizes

I'm looking for an algorithm to help me out with a combination of combinations problem. I have generated two lists of combinations of letters: (26 choose 6) & (26 choose 5) My goal is to be able ...
• 121
151 views

### Mapping match-up combinations into an integer

First of all, I want to say I wasn't sure if I should post this here or in math.stackexchange but I think the question is too programming-related to belong to the latter community. Definetly not a SO ...
• 2,126
160 views

### Restricted randomization of a binary vector

Suppose I have a binary vector of sample size N with each of the two possible values (e.g., 0 and 1 occurring equally often). For example, if N=10, the binary vector is: 0 0 0 0 0 1 1 1 1 1 Suppose ...
• 51
52 views

### What algorithm to use to count realization of high combinatorics setup?

I'll use the MobA games to illustrate what I'm asking since it's easier to explain even tho I want to apply that algorithm to time series. In a MobA game you have more than 100 characters and every ...
• 101
1k views

### Fast indexing of k-combinations

I'm revisiting an old problem that I was working on some time ago. A typical scenario is "3 bits are set within an 8 bit integer", i.e. 00000111. All unique combinations with 3 set bits can easily ...
• 785
5k views

### Algorithm to compute k-permutation without repeating and no duplicates

I have a set of integers, for example 1..20 and I want to get all possible combinations of that set drawing 5 numbers. So each combination has 5 numbers from that set of integers. But I don't want ...
1 vote
780 views

### Given an array of n bits, how to generate every permutation with i 1's and n-i 0's?

It's simple enough to brute force a collection of strings and then filter for every occurrence with the required count of 1's. As n increases the number of possible permutations becomes very large, ...
305 views

### Domain analysis for discrete values - ON and OFF points in these cases

Following my previous question (with great answer from Bart van Ingen Schenau), I noticed a discrepancy I could not wrap my head around: Bart mentioned that: The point ON the boundary is by ...
• 513
2k views

### Domain analysis - why OFF points are inside of the domain when the border is open

I have asked on a few other sites, no response but it must be something silly as many authors mention in their books. Here is the best text I found: My ultimate question is: Why the OFF point lies ...
• 513
7k views

### Number of strings containing a specific substring

I've seen numerous questions (and answers) concerning the number of binary strings (e.g "10010" containing some binary substring (e.g "00"). I'd like to know if there is a way to generalize this: ...