# Questions tagged [combinatorics]

Combinatorics is a branch of mathematics concerning the study of finite or countable discrete structures.

418 questions
Filter by
Sorted by
Tagged with
411 views

### Iterative implementation of K of N variations

Objective: Print all combinations with repetition of k elements out of a set of n elements. ...
3k views

### Compute the mean, variance and standard deviation of all pairs, triplets and sets of four

My code sample for finding the mean for the case of pairs is: ...
86 views

### Calculating how similar two objects are according to a database

I want to calculate how similar two objects are according to a database. However the code is very slow; it takes around 2 minutes to analyze just 3 objects. How can I speed it up? I have tried to ...
517 views

### Using brute force to do large scale permutations and combinations

This problem should self explanatory based on namings of variables and functions. In essence I am doing well over 720*720*90 checks/calculations. Hence, this is taking far, far too long. How do I make ...
466 views

### Efficient String permutations calculation in Java

In trying to compute permutations of a given String, what can I do to further improve the code below for memory and/or time efficiency? ...
154 views

### Pascal's triangle with libgmp and pthread in C

I have written a program to generate a pascal triangle of predefined size. Code ...
91 views

### Shortest code to generate a full mesh of elements

I am trying to find the shortest code that generates a full mesh of the elements fed into it in graphviz format e.g. the full mesh of [0, 1, 2] is: 2 -> 0 2 -> 1 1 -> 0 I have the code below and I ...
300 views

### Recursively generate combinations while using Boost Coroutines

I've tried out implementing a combination generator using boost coroutines. It accepts an array of possible values and generates one array at a time for each combination. As a limitation, it only ...
690 views

### Permutation index Python

Here is my Python code for finding the permutation index of a given digits and a target number. And by permutation index I mean, for example, given digits ...
57 views

### Calculate and plot expected value involving summations and products

I wrote a code to calculate a series of summations and products for a maths assignment I'm doing. The equation is shown below. E(\sigma)=[1-(P(\text{$1^{st}$ rejects}) \times P(\text{$2^{nd}$ ...
1k views

### Generate all permutations in Clojure

Given a set, generate all permutations: (permutations #{1 4 5}) => ((5 4 1) (4 5 1) (5 1 4) (1 5 4) (4 1 5) (1 4 5)) Here's what I cobbled together: ...
609 views

### Comparing algorithms for computing binomial coefficients in Java

I have these 3 different algorithms for computing binomial coefficients (I also had the 4th recursive one, yet I discarded it since it is super slow). The first uses the factorial formula, the second ...
304 views

### Generating vertices of the rectified hypercube

The following piece of code generates the vertices of the rectified hypercube in arbitrary dimensions. The 3D case of the rectified hypercube is a cuboctahedron with 12 vertices (±1,±1,0), (±1,0,±1), (...
2k views

### Iterative solution for generating all permutations of a string

I know the runtime for generating all permutations is supposed to be $O(n!)$. I'm not sure if the code I wrote for it runs in $O(n!)$ though. I'm having trouble analyzing its runtime. The ...
111 views

### Permutations part two

This is a follow up from this question. The goal is to make some function that can return the number of possible permutations with repetitions. As Gareth pointed out there is a nice formula for this ...
12k views

### Counting permutations without repetitions for a number or a string

Can I make the following code faster with minor modifications? It times out on CodeWars website. ...
466 views

### Computation of product of permutations

Given a graph $G = (V,E)$ with a unique labeling of each vertex, let the transposition $(i,j)$ (where $i,j$ are the labels on adjacent vertices) represent selecting an edge and swapping the ...
1k views

### Find all distinct combinations of letters in a string

I've been preparing for interviews and picking up modern C++. A recent prep question I did was to find all combinations (or distinct subsets) of letters from a string. E.g. ...
2k views

### Form every unique combination of the items of a list of lists

I've tried looking some stuff up. I thought it was transposition first, but looking at this, that's not exactly it. I hacked this code together in about 3 hours, stopping frequently due to ...
420 views

### Give the variable length permutations (combinations) of a set of strings

This code is a proof-of-concept which I intend to convert into a static utility / helper class. I'm looking at this review from a structure or performance viewpoint. Small detail such as whether it ...
1k views

### Given two strings, determine if one is a permutation of the other

After comparing my newbie attempt with other people's answers, I have a couple questions: I've made s1_set the size of s1. I've ...
64 views

### Summative Pattern

While playing around with J (link), I found that you can create a sequence of shape N0 N1 ... NK with i. taking a list as its ...
589 views

### 3D Bin Packing using Java [closed]

This is a follow up question to 3D bin packing in Java ...
675 views