Combinatorics is a branch of mathematics concerning the study of finite or countable discrete structures.
4
votes
1answer
53 views
Permutations program in Python
This code asks for letters and a number of letters per word and generates all possible permutations. Then compares those permutations with an English dictionary and creates a list with all the words ...
3
votes
1answer
72 views
Finding the 'Minimum' AND of all the possible subsets of a set
The subset size should be greater than or equal to 2.
How can I speed up this code?
...
8
votes
1answer
82 views
Verifying boardgame mathematics with MATLAB
I recently bought this math-based boardgame for my little cousins, and am now trying to verify its design with some MATLAB code. The relevant parts of the game are:
A board with numbers from 1 to ...
20
votes
3answers
320 views
Analyzing Minesweeper Probabilities
Calculating probabilities in Minesweeper might sound like an easy task, but I've seen so many probability calculators that's either incorrect, horribly slow, or with ugly code (or all of them) so I ...
6
votes
5answers
519 views
Improving efficiency of Project Euler 185 (16-place Mastermind)
This a solution for Project Euler Problem 185. It works fine for the example but slow for the problem statement. How can I improve its speed and efficiency?
...
3
votes
2answers
106 views
Calculate all possible combinations of an array of arrays or strings
I'm using code adapted from this Stack Overflow question to calculate all possible combinations from an array, which may contains strings.
For example:
...
11
votes
7answers
2k views
Is my solution to return kth row of the Pascal's triangle suitable for a job interview?
Question:
Given an index \$k\$, return the \$k\$th row of the Pascal's triangle.
For example, given \$k = 3\$, return \$[1,3,3,1]\$. Bonus points for using \$O(k)\$ space.
Can it be ...
6
votes
3answers
269 views
Get distinct combinations of numbers
The below code returns all distinct combinations based on the logic that 1,2,3 = 3,2,1 = 2,3,1, so it only returns 1 instance of that set of numbers.
...
1
vote
1answer
44 views
Find triangles from line
I have some lines that form triangles. I'd like to challenge the fastest way to find all triangles.
In particular the code should take an ArrayList of Line2D object and return an ArrayList of ...
7
votes
2answers
72 views
Simplified Bin Packing using JavaScript
This code determines the maximum number of boxes (one size) that can fit into the back of a truck, checking all possible orientations to ensure maximum Bin Packing excitement. This is (hopefully) the ...
6
votes
1answer
132 views
Given a shape, return all triangles that can be formed
Given a shape, get all triangles that can be possible by connecting the points.
Example: given 3 points, only 1 triangle is possible, but given a pentagon, 10 are possible.
Also the ...
3
votes
4answers
124 views
Better way to achieve looped output result
I have 4 variables - say A, B, C and D
Each variable can have 4 values - say 1, 2, 3 and 4
I need to generate all possible combinations of values
Example of Expected Output:
...
3
votes
2answers
58 views
Curious fractions in functional Ruby
Problem 33 in Project Euler asks:
The fraction 49/98 is a curious fraction, as an inexperienced
mathematician in attempting to simplify it may incorrectly believe
that 49/98 = 4/8, which is ...
7
votes
1answer
101 views
Speeding up subset sum implementation
Important fact: the number of the input is greater than 1. How do I use this fact to speed up this solution?
...
7
votes
3answers
206 views
Optimizing unique partitions of integers
I am working on a project involving the unique partitioning of integers. I.e. I am looking to have all of the partitions of n = x1 + x2 + x3 + ... + xk, where xi = xj implies i = j.
For example, if I ...
7
votes
1answer
71 views
Compute stats on two class vectors
Below is a full working code example of code which is used to compute stats on two class vectors (partitions).
There are two functions:
pairwise_indication and
...
10
votes
2answers
120 views
Printing permutations of a given string
I want some feedback on the program I developed in C for printing the permutations of a given string.
...
0
votes
1answer
89 views
Finding the number of permutations of an integer array with equaling difference (not in order)
The array size is <= 16. The difference is defined as:
diff[i] = array[i+1] - array[i];
I need to find the number of permutations of the original array, which ...
3
votes
0answers
252 views
Nonogram puzzle solution space
I've written some code to brute-force enumerate the solution space of nonogram puzzles up to a certain size. It does a good job up to the first ~4 billion puzzles, but I run out of disk space to store ...
7
votes
2answers
129 views
Generate permutations with symbols
Goal: Create a combination of emails based from inputted first name, last name, middle name, and a domain. Add in common separators. Then I'll check which one is correct with the rapportive API. This ...
4
votes
3answers
229 views
Prints out all ways to multiply smaller integers that equal the original number
Write a program in Java that takes a positive integer and prints out all ways to multiply smaller integers that equal the original number, without repeating sets of factors. In other words, if ...
1
vote
0answers
56 views
Find the combinations, given three datacenters with x number of machines [closed]
I am working on a project in which I have three datacenter (as of now) and each datacenter will have some machines.
So I am storing the input in a ...
5
votes
1answer
111 views
Project Euler #15 in haskell
I've solved Project Euler #15 in Haskell, but I feel like there might be a better way to express my solution that I'm not seeing. I start out defining my types:
...
3
votes
2answers
440 views
Permutation of a string eliminating duplicates
This code lists the permutations of the string, and eliminates duplicates if any.
I'm looking for code review, best practices, optimizations etc.
Also verifying complexity: O(n! * n) as time ...
1
vote
3answers
2k views
Calculate all possible combinations of given characters
I was asked in my textbook Lectures on Discrete Mathematics for Computer Science to construct a program that would take an alphabet ({a,b,c} or any combination of ...
5
votes
2answers
160 views
Print routes on the stairway when only 1 or 2 steps are possible
Given a staircase with N steps, you can go up with 1 or 2 steps each
time. Output all possible ways you go from bottom to top.
I'm looking for code review, best practices, optimizations etc. ...
3
votes
1answer
200 views
Find all permutations of a string in C++
I need a review of the following code for finding all permutations of a string in C++:
...
10
votes
3answers
2k views
Brute Force Algorithm in C
This is a simple brute force algorithm I have in C. All the program does it print out every possible combination of the given alphabet for the given length.
I ...
0
votes
1answer
330 views
2
votes
1answer
47 views
Produce product of lists
I want to combine elements in different lists.
For example, here are 3 lists.
list_a : [ 1,2,3 ]
list_b : [ 4,5,6 ]
list_c : [ 7,8 ]
Selecting elements from ...
3
votes
2answers
115 views
Determine if a word can be constructed from list of subsets - follow-up
I have reworked my code as suggested from my previous question: Determine if a word can be constructed from list of subsets.
Please instruct me on the complexity along with a review feedback, as ...
2
votes
2answers
125 views
Determine if a word can be constructed from list of subsets [closed]
The question is explained well by examples in the comments below. Also I request verifying complexity: O( n * n!), where n is the number of words in the subsets. Review my code for optimizations, ...
4
votes
2answers
135 views
Integer Partition using an iterator
I tried implementing Integer Partition (enumerating all possible sets of whole numbers whose sum is a given integer).
Looking at @rolfl's answer, I reasoned that with a stack data structure, we ...
3
votes
3answers
168 views
Permutation algorithm: What is so bad about this code?
I was asked to write a permutation algorithm to find the permutations of {a,b,c}. Since this is a famous question to which an answer is readily available online, I wanted to do it a little ...
6
votes
2answers
101 views
Integer Partition
The aim is to enumerate all possible sets of whole numbers whose sum is a given integer.
...
3
votes
1answer
91 views
Better way to create samples
I've done this piece of code for creating all possible samples without repetitions, but I think that it is a so heavy algorithm because every time I call this recursive function I create a new vector ...
19
votes
6answers
1k views
How can I make this mess of Java for-loops faster?
I'm trying to find all the 3, 4, 5, and 6 letter words given 6 letters. I am finding them by comparing every combination of the 6 letters to an ArrayList of words ...
6
votes
1answer
5k views
Find all subsets of an int array whose sums equal a given target
I am trying to implement a function below:
Given a target sum, populate all subsets, whose sum is equal to the target sum, from an int array.
For example:
...
1
vote
1answer
65 views
Increase efficiency of card-ordering program
As mentioned in @rolfl comment. What this program does is that it "resequences the cards using a fixed system and count the number of times the resequencing happens before the output is the same as ...
3
votes
0answers
45 views
TLE for SPOJ Upper Right King
I am solving this problem on SPOJ Upper Right King (Hard).
I've written a solution in Python with a time complexity of O(n(logm)2). But it's showing TLE. Can anyone help me out with this?
For more ...
2
votes
0answers
538 views
Ugly numbers problem
Taken from one of codeeval.com challenges:
Challenge Description:
Credits: This challenge has appeared in a Google competition before.
Once upon a time in a strange situation, people ...
3
votes
2answers
183 views
Improving run-time and max-digits of digit summing code
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 ...
3
votes
1answer
132 views
How to improve this permutations program?
I wrote a small program which shows all possible permutations of choosing m integers from the set {1, 2, ..., n}, as follows:
...
2
votes
1answer
184 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
1k 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 ...
1
vote
0answers
92 views
How to make python knapsack program faster
I have knapsack problem:
I have data:
List of product prices = MENU
Most popluar product count = MOST_POPULAR_COCKTAIL
Knapsack price = CASH
Knapsack length = CHECK_LEN
I need get all knapsack ...
1
vote
1answer
136 views
How to make this algorithm faster?
It works fine, but it is slow.
Could anybody help make this faster?
...
3
votes
2answers
293 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 ...
2
votes
1answer
285 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.
...
1
vote
1answer
90 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, ...