Combinatorics is a branch of mathematics concerning the study of finite or countable discrete structures.
-4
votes
0answers
11 views
Specific combinations with numbers 1 to 63 ,set 7 (63*63/7=567) [on hold]
Hello I'm a student and I need this type of combinations to write in java or just notepad but I don't know how to do...I know how to make fullcombinations of everynumber...but I want this kind : Range ...
2
votes
2answers
50 views
Nsum problem: find all n elements in an array whose sum equals a given value
I am implementing the algorithm for the following problem with Python. I am pretty new to Python, so I want to listen to any advice that improve my coding style in a "pythonic" way, even about naming ...
14
votes
4answers
585 views
Count number of ways to paint a fence with N posts using K colors
A friend sent me this question, and I'd love somebody to review this and give his opinion.
Write an algorithm that counts the number of ways you can paint a
fence with N posts using K colors ...
0
votes
1answer
47 views
Generating all possible permutations of the string
This generates all possible permutations of the string. I am also unable to understand the time complexity of this problem. Can someone please explain the complexity to me?
...
3
votes
1answer
45 views
Python small brute-forcer
I have 20+ key set. Keyset is like:
Key[0] = { "PossibleKey0", "PossibleKey0Another", "AnotherPossibleKey0" }
Key[1] = { ....
There is an encryption which needs ...
13
votes
1answer
115 views
Advanced and Detailed Minesweeper Probabilities
In an earlier question, I showed my code for calculating the mine probability for each and every field in a Minesweeper board. But it doesn't stop there. In that very same Minesweeper Analyze project, ...
8
votes
2answers
123 views
A Specific Combination
This code is going to be included in my Minesweeper Probabilities project. (so far it only exists on the develop-branch)
The purpose is to return a specific combination, let's say for example that ...
2
votes
3answers
82 views
Finding combinations of 3 numbers
What this code tries to do is find possible combinations of three numbers. For example, let's say I have the following numbers:
1, 2, 3, 4, 5, 6, 7
Some ...
5
votes
2answers
75 views
'Countdown' Numbers round - combine numbers arithmetically to reach a target
Countdown is a British gameshow where contestants compete in word and number challenges. During the numbers round, six numbers are chosen semi-randomly and the task is to combine them using addition, ...
1
vote
1answer
80 views
Print all permutations of a given string in Java
I want to print all permutations of a given string in Java. To do this I create one auxiliary array boolean used[] to check if I have used some character or not.
...
4
votes
1answer
126 views
Print all possible combinations of size r, from an array of size n
This is my working solution for the following problem: given an array of integers of size n, print all possible combinations of size r.
Before I proceed to the solution, I have the following ...
1
vote
1answer
53 views
Combinations with replacement
I am still new to Scala and wrote a small snippet to find all the combinations with replacement of a sequence (e.g. cwr(ab, 3) should give aaa, aab, abb, bbb).
The slow way would be to generate all ...
4
votes
1answer
164 views
Recursive function that generates the permutations of a string
I am looking for a review of my recursive function that generates the permutations of a string. Are there better ways to do this?
...
6
votes
2answers
89 views
How can I optimize this combination method?
I have this method that is working perfectly fine, but it's very slow, and sometimes I have to wait 15 minutes to get a good result, which is ok. I'm wondering if I can make it faster.
Basically I'm ...
4
votes
3answers
120 views
Another permutator
This is a solution to this problem. The problem statement:
write a program to display all possible permutations of a given input
string--if the string contains duplicate characters, you may have
...
6
votes
1answer
55 views
Generating Cartesian product of strings in R
Sometimes I need to create character vectors like this one:
...
5
votes
2answers
104 views
Binomial coefficient
I wrote a C++ function to calculate the binomial coefficient, trying to avoid overflows as much as possible.
...
5
votes
2answers
74 views
Possible combinations following a rule
The problem is the following:
We have a number of months to buy a number of supplies. The sooner we finish buying them, the better, but we don't know how much we can buy per month and would like to ...
4
votes
1answer
113 views
Seeking improved Objective-C permutation algorithm
This algorithm seeks to find all of the possible permutations of a word:
...
12
votes
3answers
462 views
Generate all possible combinations of letters in a word
This is a JavaScript function that returns ALL the possible combinations of whatever word the user enters. I am looking to clean this code up a bit...any and all suggestions are welcome!
...
4
votes
1answer
106 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
88 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
101 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 ...
21
votes
3answers
474 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
575 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
510 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:
...
13
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 ...
7
votes
3answers
610 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
48 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
87 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
143 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 ...
4
votes
4answers
132 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
3answers
71 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
102 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
225 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
193 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
114 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 ...
4
votes
0answers
300 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
137 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
380 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
62 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
119 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
831 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
5k 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
190 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
407 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
3k 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
483 views
2
votes
1answer
51 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 ...