Questions tagged [combinatorics]

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

Filter by
Sorted by
Tagged with
3
votes
2answers
311 views

Max-digits of digit summing

As a challenge I decided to do the following problem: How many different numbers with n digits are there whose digits add up to k? As this is an embarrassingly parallel problem I decided to use a ...
-3
votes
1answer
170 views

Distinct triple sums

Here is my code. It works fine but I need to make the code more efficient. ...
4
votes
1answer
1k views

Showing all possible permutations from a set

I wrote a small program which shows all possible permutations of choosing m integers from the set \${1, 2, ..., n}\$, as follows: ...
3
votes
1answer
1k views

Python infinite product generator

I have the code below to get an infinite generator of the products of an iterable (e.g. for the iterable "ABC" it should return A, B, C, AA, AB, AC, BA, BB, BC, CA, CB, CC, AAA, AAB, AAC etc. ...
6
votes
2answers
4k views

Permutation of given string

I am reading a book on DSA, and the author explains how to generate the permutation of strings using recursion. I want to know if there are better ways of doing the same, unless this is the best ...
3
votes
0answers
437 views

Python knapsack program

I have this data for the knapsack problem: List of product prices = MENU Most popular product count = MOST_POPULAR_COCKTAIL ...
2
votes
1answer
478 views

Find all row combinations which sum elements equal to any given number

It works fine, but it is slow. Could anybody help make this faster? ...
3
votes
2answers
1k views

Computing the number of permutations of n consecutive numbers

I'm just starting to learn C++ and have been experimenting with various functions. Here is one that computes the number of permutations of n consecutive numbers as well as all possible permutations ...
3
votes
2answers
361 views

My implementation of lexicographic permutation in F# is 3x slower than C#

Can someone help me with the following micro optimization for the F# code for lexicographic permutation? I have code in C# which runs for 0.8s. As a learning practice, I translated it into F#. ...
4
votes
3answers
559 views

Optimizing sum_combination_for(n) code

I'm working on a piece of code for calculating all the possible combinations of numbers that sum to n. For example: ...
2
votes
1answer
1k views

Generating permutations with repetitions of string

I have written the below code which generates all possible permutations with repetitions of a string. I want to make this program shorter and much faster, but I don't know how to do that. ...
7
votes
4answers
1k views

Printing all binary strings of length n

I have completed my homework with directions as follows: Declare and implement a class named Binary. This class will have a method named printB(int n) that prints all binary strings of length n. ...
1
vote
1answer
500 views

Any way to optimize or improve this python combinations/subsets functions?

I believe this is essentially the same method as the itertools.combinations function, but is there any way to make this code more more perfect in terms of speed, ...
2
votes
2answers
2k views

multi-recursive replacement function

I wrote a function for creating all possible translations of a source string, based on a multiple translation map. It works, but generates a lot of intermediate maps (see line marked with *). Is there ...
2
votes
1answer
339 views

Discovering words from letters in Clojure (Letterpress Solver)

I created a Letterpress solver that will take a string of letters and return a list of valid words that can be constructer with the provided letters. Not all letters need to be used in each word. ...
5
votes
2answers
229 views

Finding perimeters of right triangles with integer-length legs, up to a limit

I have a nested for-loop that populates a list with elements: ...
3
votes
1answer
115 views

Producing all allocations by n items from a list

I have strong feeling that the code below is ugly at least as there are 2 same "cons". I would appreciate if you advise me ways to improve it. The code produces all allocation by n items from list ...
14
votes
4answers
2k views

Exhaustive search for encryption keys

This does the job, but is not especially elegant. What is the preferred Pythonic idiom to my childish nests? ...
3
votes
2answers
3k views

Getting all (forward) permutations of a list of strings

I have the following concise-ish (and working) approach to getting all the forward permutations of a list of string. So with the list: w = ["Vehicula", "Sem", "Risus", "Tortor"] the results ...
6
votes
2answers
2k views

Combinations of list elements

It was written in Emacs Lisp and requires Common Lisp loop facility. Can this code be improved? Did I hit any anti-patterns along the way? ...
2
votes
2answers
2k views

Print all interleavings of two given strings

Given two strings str1 and str2, write a function that prints all interleavings of the given two strings. You may assume that all characters in both strings are different Example: ...
2
votes
1answer
159 views

Counting the ways to pick increasing sequences from sorted arrays

Preamble I am trying to learn JavaScript by writing code and looking up documentation, one problem at a time. I am already familiar with several "dynamic" languages, so I'm hoping to be productive ...
11
votes
2answers
7k views

Print all permutations with repetition of characters

Given a string of length n, print all permutation of the given string. Repetition of characters is allowed. Print these permutations in lexicographically sorted order Examples: Input: AB ...
3
votes
1answer
6k views

Generating all subsets of a given set

I am learning Java Collections Framework. Can someone look at this code for generating all subsets of a given set and tell me any issues with it. ...
4
votes
1answer
335 views

compression condition permutation

I have 16 permutations each with 104 variables using the standard alphabet. The 104 variable permutation is selected based off of compression complexity. This is one example of the pattern I am able ...
6
votes
1answer
9k views

Generating words based on a list of letters

I wrote a program to take a list of letters and from every permutation of them and check that against the dictionary and print out valid words. The constraints are that there is a control letter ...
7
votes
1answer
2k views

Pairwise Combinations Generator

Below is an algorithm to generate all pairwise combinations for a set of random variables. See here for an explanation of what constitutes a minimal all-pairs set. The algorithm below works but I feel ...
2
votes
2answers
3k views

Printing nth bell number

Bell number \$B(n)\$ is defined as the number of ways of splitting \$n\$ into any number of parts, also defined as the sum of previous \$n\$ Stirling numbers of second kind. Here is a snippet of ...
8
votes
2answers
31k views

Permutations of a list of numbers

I have written a program to find all the possible permutations of a given list of items. This precisely means that my program prints all possible P(n,r) values for r=0 to n. ...
41
votes
1answer
2k views

Finding minimum scalar product using ST Monad

Inspired by a Stack Overflow question, I decided to practice my Haskell by taking a crack at the Google Code Jam's Minimum Scalar Product problem: Given two vectors \$\mathbf{v_1}=(x_1,x_2,\ldots,...
5
votes
1answer
1k views

Enumerate k-combinations in Clojure (P26 from 99 problems)

I've been playing with Clojure for the last few evenings, going through the well known 99 problems (I'm using a set adapted for Scala). Problem 26 Given a set S and a no. of items K, returns ...
2
votes
3answers
916 views

Permutations Finder Help Number 2

Previous question: Java application for finding permutations efficiently> I have changed quite a bit of code, and need some more reviews. ...
81
votes
9answers
124k views

Generating all combinations of an array

I'm generating all combinations of an array, so for instance, ["a", "b", "c", "d"] will generate: ...
8
votes
1answer
761 views

Java application for finding permutations efficiently

I am an eighth grader with a school project of creating and application in Java that returns the total permutations of two given numbers. It needs to be light and efficient, for later deployment on a ...
0
votes
1answer
473 views

Finding columns of a matrix that are the same for combinations of events

How I can change this multi-loop to reduce the computation time? A is a matrix (5 × 10000) where the fifth line contains values between 1 and 50 corresponding to ...
2
votes
1answer
338 views

Organizing matches between sports teams

How could I improve this algorithm? The goal is to organize matches between sport teams such that: Each team affront each other A minimum number of team should start a match after just finishing one ...
19
votes
4answers
15k views

Finding all k-subset partitions

The following code generates all \$k\$-subsets of a given array. A \$k\$-subset of set \$X\$ is a partition of all the elements in \$X\$ into \$k\$ non-empty subsets. Thus, for ...
5
votes
2answers
8k views

Python generator function that yields combinations of elements in a sequence sorted by subset order

In Python, itertools.combinations yields combinations of elements in a sequence sorted by lexicographical order. In the course of solving certain math problems, I ...
4
votes
3answers
3k views

Generating permutations and combinations

How can this code be improved? ...
7
votes
2answers
13k views

Splitting an array of numbers into all possible combinations

This takes an array of numbers then splits it into all possible combinations of the number array of size 4 then in another array puts the leftovers. As I want to take the difference in averages of ...

1
5 6 7 8
9