Tagged Questions

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

9 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: ...
40 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 ...
63 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), (...
86 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 ...
51 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 ...
2k 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. ...
127 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 ...
52 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. ...
31 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 ...
34 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 ...
40 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 ...
79 views

3D Bin Packing using Java

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

94 views

Scala implementation of @rolfl's integer-partitioning algorithm

While reviewing @Martijn's Distinct sums of integers (finding all combinations of positive integers that sum to a given number), I proposed the following solution: ...
66 views

C permutation generator

I am making a permutation generator in c. Any ideas how I can make it faster? ...
91 views

Searching a string for any permutation of words

Given a string and an array of words, return all indexes in string for which a concatenation of all words in the array, in any order (so ["eensie", "weensy", "spider"] has six orderings) can be ...
137 views

Recursive program for generating and printing all permutations of the numbers 1, 2, …, n for given integer number n

I've just written code for generating all permutations of the numbers from 1 to n in Java. It seems to work, but I think it's a bit more complex than it needs to be. ...
111 views

Permutation function in C#

One thing lead to another and eventually I wanted to know the "proper" way of writing the permutation generating function in C#. Below is my code for generating permutations. This will go into an ...
572 views

isPermutation method

I wrote an isPermute method. Can I get some tips and advice on better coding style? ...
968 views

Printing all possible sums of two n-sided dice rolls

For my CS class, we were tasked with writing a program that calculates all the possible results from rolling two n-sided dice. For example, the input of 4 would ...
62 views

Finding tuples of numbers subject to constraints

I just watched the video from "Think Like a Programmer, Episode 2: Puzzles & Problems". The problem is: Assign number 1-7 to three departments in a city: Fire, Police, Sanitation. ...
158 views

Finding permutations of a word

This was a basic anagram problem. Take an input word, find all its permutations, then check a dictionary file to see what if any of those are real words. Dictionary file My input data: ...
148 views

Counting paths in an n-dimensional grid that stay within the boundaries

Problem Statement You are situated in an N dimensional grid at position (x1, x2, …, xN). The dimensions of the grid are (D1, D2, …, DN). In one step, you can walk one step ahead or behind in ...
280 views

Programming Challenge from Kattis: Apparatus

I am trying to solve apparatus problem, paraphrased below. There is an apparatus with n on/off switches with a one-to-one correspondence to n lights (but with an unknown permutation). We have ...