# 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.

37 questions
Filter by
Sorted by
Tagged with
4answers
187 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 ...
4answers
388 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 ...
2answers
118 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 ...
2answers
191 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" ...
3answers
384 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 ...
1answer
218 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 ...
2answers
203 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 ...
1answer
97 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 ...
1answer
239 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 ...
1answer
134 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 ...
2answers
138 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 ...
1answer
78 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 ...
1answer
82 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 ...
2answers
284 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 ...
1answer
153 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 ...
2answers
3k 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 ...
1answer
191 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 ...
1answer
513 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, ...
2answers
708 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 ...
1answer
77 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. ...
3answers
367 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 ...
1answer
91 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 ...
1answer
135 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 ...
0answers
411 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 ...
1answer
635 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 ...
2answers
874 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 ...
1answer
149 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 ...
3answers
155 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 ...
0answers
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 ...
1answer
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 ...
1answer
4k 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 ...
2answers
688 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, ...
0answers
289 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 ...
3answers
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 ...
3answers
6k 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: ...
1answer
673 views

### Number of sequences when no adjacent items can be the same

I came across this one problem, There is a particular sequence only uses the numbers 1, 2, 3, 4 and no two adjacent numbers are the same. Write a program that given n1 1s, n2 2s, n3 3s, n4 4s ...
1answer
1k views

### How do I create every permutation [closed]

I have a list of letters, this is just an example list: ['a','b','c','d','e'] How do I compute every combination of the list? The letters cannot repeat, for example. a,b,c,d,e a,c,b,d,e a,c,d,b,e a,...