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

learn more… | top users | synonyms

0
votes
1answer
27 views

Print all combinations of points that can compose a given number [on hold]

Could someone please explain why this works? After trying for hours I think I got the answer. But I don't quite understand it. https://jsfiddle.net/d2Lft7d1/ ...
1
vote
2answers
91 views

Python one-liner to print permutations of a string

I have written a Python one-liner that permutes a given string. I wrote this just for fun using list comprehensions and I would like to get feedback from the community. ...
2
votes
1answer
41 views

k-combinations in lexicographic order (using given algorithm)

I already solved the problem, but it seems my code is too awkward, and with a different approach there could be a more elegant solution. Notice that the general algorithm is described in the ...
3
votes
2answers
141 views

Finding integer lengths for a right triangle with a given perimeter

I'm using Python 3 and have written this code to find the right triangle sides when given the perimeter: ...
6
votes
2answers
109 views

Building a set of all subsets recursively in C++

Here is my recursive implementation of a power set function in C++. One thing that concerns me is that I am iterating over the set of sets while modifying its size. The code nevertheless functions as ...
3
votes
2answers
89 views

Finding Permutations of Numbers

I'm trying to solve this challenge, which consists of finding the next biggest number formed by the digits of the passed in number. If it is impossible to find a number larger than the passed in ...
1
vote
2answers
47 views

SPOJ - Alphacode - Exceeds Time Limit

I'm trying to solve Alphacode on SPOJ. The challenge is to count the ways to split a string of up to 5000 digits into a sequence of numbers, each ranging from 1 to 26. It works fine for small ...
5
votes
2answers
48 views

Expand string patterns in Elisp

I need to expand logical patterns to list of strings. For example I have the following definition: ...
0
votes
1answer
51 views

Iterative “counting change” implementation in mit-scheme

Here is my iterative implementation of the Counting change example in SICP. Please note that I'm a beginner, which means I only know the basic syntax for the time being. Requirement: How many ...
5
votes
2answers
141 views

Calculating the count of integer partitions of a number (uses stateful vectors internally)

I've written a Haskell function to count the number of partitions of an integer - it's basically an implementation of the same algorithm as this one, using Euler's Pentagonal Number Theorem: $$P(n) = ...
3
votes
2answers
65 views

Equivalents permutations function

My function is supposed to essentially give the cartesian product of all the letters in a string with the caveat that you have to give the permutations of every equivalent of each character in a ...
2
votes
1answer
77 views

Producing residues of combinatorics on strings

Basically, this code does multiplication of chosen operations. ...
2
votes
0answers
92 views

Generating all unique permutations of a string

Here is a plan for generating the permutations of S: For each item x in S, recursively generate the sequence of permutations of S - x, and adjoin x to the front of each one. This yields, for each ...
0
votes
1answer
80 views

All permutations of integer vector

I have spent a decent amount of (waaay too much) time trying to write the below function and get my head around recursion. The aim was to return all permutations of an int vector (assuming no ...
0
votes
0answers
89 views

All combination of character alphabet

I write this code to find all combination of an alphabet z={A,B,C...N}. In DNA case,we use z={A,C,T,G},then the function Words and ...
1
vote
2answers
97 views

Generalizing a choose operation

Consider the following piece of code. ...
0
votes
1answer
111 views

Subset sum simple iterative implementation

Here is the simplest iterative implementation of Subset sum problem that I could come up with1, as a follow up to this recursive implementation of the same problem: ...
3
votes
2answers
297 views

Subset sum problem implementation

Here is a recursive implementation of the Subset sum problem: ...
5
votes
1answer
92 views

Iterative implementation of K of N variations

Objective: Print all combinations with repetition of k elements out of a set of n elements. ...
3
votes
1answer
74 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: ...
4
votes
1answer
64 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 ...
1
vote
1answer
87 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 ...
1
vote
1answer
72 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? ...
1
vote
2answers
43 views

Pascal's triangle with libgmp and pthread in C

I have written a program to generate a pascal triangle of predefined size. Code ...
2
votes
1answer
32 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 ...
1
vote
0answers
64 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 ...
4
votes
1answer
60 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 ...
2
votes
0answers
44 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}$ ...
1
vote
1answer
183 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: ...
6
votes
3answers
124 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 ...
4
votes
1answer
87 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), (...
2
votes
1answer
174 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 ...
1
vote
1answer
63 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 ...
11
votes
3answers
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. ...
5
votes
1answer
145 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 ...
2
votes
1answer
104 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. ...
3
votes
1answer
41 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 ...
1
vote
0answers
101 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 ...
5
votes
0answers
43 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 ...
0
votes
0answers
221 views

3D Bin Packing using Java

This is a follow up question to 3D bin packing in Java ...
4
votes
2answers
79 views

all combinations of all sizes less than N

I want to generate all possible combinations (without duplicates) of all sizes less or equal than \$N\$, so for example if \$N=3\$ I want to generate the following \$\{1\},\{2\},\{3\}, \{1,2\},\{1,3\},...
2
votes
1answer
91 views

Permutations with repetitions algorithm in R

Given a string of length n, print all permutation of the given string. The code bellow generates all permutations (with repetitions) for the given string and stores them in object ...
3
votes
1answer
291 views
2
votes
1answer
141 views

3D bin packing in Java

I made some changes to the first code here I wrote and I want to know which one is more correct logically (before the changes or after the changes). It's really hard to manually test these kind of ...
3
votes
2answers
407 views

3D bin packing algorithm using Java?

I wrote a 3D bin packing algorithm but I am still not sure if it is correct or not. I did not follow any code or pseudo-code that's why I would like to know if it is an efficient algorithm for the 3D ...
9
votes
2answers
180 views

Finding all contiguous sublists such that each member appears an even number of times

The program needs to find all contiguous sublists of numbers where the number of occurrences of every member in the contiguous sublist is divisible by 2. The first line of input is N (the number of ...
5
votes
2answers
736 views

Java 8 Stream to produce all permutations of an array using recursion

I want to write a class that returns a Stream of permutations of an int[]. ...
9
votes
5answers
278 views

Pizza Hut math problem #1 in Haskell

I'm currently attempting to learn Haskell after a fair history of imperative programming. When I saw the Pizza Hut Pi Day math problems, I thought the first one would be a good candidate for my ...
2
votes
1answer
63 views
1
vote
1answer
106 views

Finding Kth Permutation Sequence

I have written a program to display the kth permutation sequence of a string made up of letters 'O' and 'Z' . I tried optimizing it but my code have not passed test cases due to timeout issues.Looking ...