Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

3
votes
2answers
157 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 ...
0
votes
1answer
87 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
votes
1answer
135 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
votes
1answer
106 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 ...
1
vote
2answers
121 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 ...
-6
votes
1answer
71 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 ...
-1
votes
1answer
72 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 ...
0
votes
2answers
247 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
1answer
99 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 ...
5
votes
2answers
2k 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
votes
1answer
120 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 ...
2
votes
1answer
440 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, ...
0
votes
2answers
195 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 ...
0
votes
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. ...
9
votes
3answers
324 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 ...
0
votes
1answer
68 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 ...
-1
votes
1answer
127 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
0answers
305 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 ...
0
votes
1answer
333 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 ...
1
vote
2answers
669 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 ...
0
votes
1answer
146 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 ...
4
votes
3answers
150 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 ...
0
votes
0answers
51 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 ...
11
votes
1answer
854 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 ...
3
votes
1answer
2k 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
2answers
475 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, ...
0
votes
0answers
242 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 ...
2
votes
3answers
1k 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 ...
6
votes
3answers
5k 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: ...
0
votes
1answer
632 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 ...
0
votes
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,...