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

learn more… | top users | synonyms

3
votes
2answers
63 views

Check is_permutation on a pair of same sized arrays

After considering the suggestions of my previous question Check whether given a pair of arrays are permutation of each other, I changed the code. Resolved the bug reported earlier In place of ...
7
votes
1answer
73 views

Calculating 24 from 4 numbers (math Poker game)

This is a game of math in Poker. Two people each have a pile of cards. They then each place 2 cards on the table at the same time. Every card is treated as a number. The players need to find a way to ...
0
votes
1answer
42 views

Generate all permutations

I have written this Java snippet to generate all permutations of a given array of integers. Can somebody review it and give some pointers as to how to make it more generic? I.e. instead of dealing ...
3
votes
2answers
72 views

Simple Factorial Interview Task

I did this code for an interview. Can you tell me how it looks? I didn't get the job, so I'm wondering what I could do better in my code. ...
12
votes
2answers
186 views

Finding a word within a pre-defined set using a search string with wildcards

The other day I was intrigued by this question (originally from here): Write a program that answers YES/NO search queries containing * placeholders. Example: if the data you have is (hazem, ...
3
votes
1answer
64 views

Letter Combinations of a Phone Number

I was asked to code a solution in Python in 15 mins. Print all possible word combinations for a given phone number. Numbers 0 and 1 will not be part of the phone number, the numbers can be repeated, ...
0
votes
1answer
62 views

Optimizing Diwali Lights problem in C

I was trying to solve the Diwali Lights challenge on HackerRank. Problem Statement On the eve of Diwali, Hari is decorating his house with a serial light bulb set. The serial light bulb set ...
2
votes
2answers
86 views

Pascal's triangle in PHP

Are there any optimization suggestions? ...
3
votes
0answers
52 views

Generating all permutations of a template pack

AllPermutedPacks<Pack<Types...>>::type is to be the pack of packs consisting of all permutations of Types.... For ...
0
votes
1answer
40 views

Permutations of a string

I wrote the following code to permute the characters of a string assuming there is no repeated character. I also want to make sure the space complexity of this algorithm is \$O(n*n!)\$: There are ...
1
vote
0answers
33 views

Approximately putting integers into buckets such that the sum of bucket differences is minimized

I have the need for load balancing in my MSD-radix sort routine and doing it optimally is not an option. So I tried to play with two simple routines for putting integers into a prespecified amount of ...
1
vote
2answers
78 views

Print all combinations

Question: ...
0
votes
2answers
85 views

Two permutation iterators for classes in Python with and without a generator

I am just testing out a couple of small classes for learning purposes. Here is my current working code: ...
4
votes
4answers
146 views

Finding Lottery odds - Topcoder #268

I have implemented the question #268 from Topcoder. The question is that there are 4 conditions for a lottery ticket: CHOICES - numbers available (10 ≤ CHOICES ≤ 100) BLANKS - number of numbers that ...
4
votes
1answer
51 views

String manipulations (reverse a string by characters, permutation)

I'm trying to solve simple Java problems in various ways. Could anyone comment about the code, like how it could be better, and what could be a problem? ...
2
votes
1answer
65 views

Accessing list elements when counting the number of rectilinear paths

I am trying to solve the RIVALS problem on SPOJ: Starting from (0, 0), how many paths are there to reach point (X, Y), only taking one-unit steps moving to the right or up? Constraints: 0 ≤ X ≤ 106, ...
10
votes
1answer
101 views

Minesweeper analyze goes to N-Queensland

As @rolfl recently solved the N-Queens problem, I figured that it was time also for me to solve it. My approach is significantly different from @rolfl's. I quickly realized that the N-Queens problem ...
5
votes
3answers
442 views

Truth Table Calculator

In of my software engineering classes, I had to write a truth table calculator in the language of my choice. This is what I came up with, and I would like to know what I should do better next time: ...
1
vote
1answer
37 views

Print all subsets and permutations of a string

The following code is designed to accept a string from the user that is at most 5 characters long. It will then find each possible substring of the string and print all possible permutations of each ...
8
votes
3answers
358 views

Pairwise combinations of an array in Javascript

I wrote a Javascript function that seems to successfully generate the unique pairwise combinations of a list: ...
5
votes
1answer
152 views

Tracking Eye Movements

The following class (that was my first class ever in python) was used in an eye tracking context. Imagine a context where you always will have a single gaze-point and some closed contours. How can I ...
5
votes
3answers
221 views

Finding the given word from jumbled letters

I have tried to write JavaScript code to check whether I can form a word from the given string (jumbled): ...
3
votes
2answers
124 views

Print all permutations with some constraints

I've the following problem: Print all valid phone numbers of length n subject to following constraints: 1.If a number contains a 4, it should start with 4 2.No two consecutive ...
-2
votes
1answer
60 views

Generating all permutations of a list [closed]

I'm looking for feedback on the following functions to generate permutations of a list. I'm new to programming and did this as an exercise after taking an on line algorithms course. I think it is ...
3
votes
1answer
78 views

Decompose a value as a sum of square numbers

My daughter had a question on her maths homework which was to write a value as a sum of 4 or fewer square numbers. For example, x = 73 could be 36 + 36 + 1. I came up with a really brute force ...
3
votes
3answers
70 views

Listing the representations of integer M as a sum of three squares M = x^2 + y^2 + z^2

I am trying a number as the sum of 3 squares. For my particular project I will require a complete list since the next step is to compute nearest neighbors (here). In any case we'd like to find \$ M ...
5
votes
3answers
257 views

Compute (x+yCx)%mod

I want to compute, as quickly as possible, $$ \dfrac{(x+y)!}{x!y!} \mod m $$ with \$x,y \le 10^6\$ and a prime \$m=10^9+7\$ (called mod in my code). My current ...
13
votes
2answers
780 views

TopCoder problem “Lottery” - SRM 144 (Division I Level Two)

The problem statement Summary: The rules of a lottery are defined by two integers (choices and blanks) and two boolean variables (sorted and unique). choices represents the highest valid number ...
12
votes
3answers
1k views

Random permutation of int[] and ArrayList<Integer>

I wrote a simple program using int[] and ArrayList<Integer> which aims to get a random permutation output between 1 to 10, ...
6
votes
1answer
486 views

Generate Cartesian product of List in Java

My code, which generates Cartesian product of all lists given as arguments: ...
8
votes
2answers
137 views

Optimizing String combinations in Java

I need to obtain all combinations of a String of length k from the given elements. For example, for ...
5
votes
4answers
263 views

Character permutations - Revisited

Several hours ago I posted this question about Generating character permutations in Python. User rolfl said that my main problem was not using the right tool for the job, as Python is interpreted it ...
3
votes
2answers
331 views

Generating character permutations

I want to generate a 'dictionary' containing all 8 character permutations of upper-case letters such that the output file looks like: ...
3
votes
2answers
82 views

A (basic) Knights and Knaves Solver

In case you're not familiar with Knights and Knaves, it's a classic type of logic problem. Here's an example: "A very special island is inhabited only by knights and knaves. Knights always tell ...
2
votes
1answer
884 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
972 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
1k 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
52 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 ...
21
votes
3answers
276 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
173 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
290 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
130 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
814 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. ...
5
votes
1answer
3k 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
64 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 ...
5
votes
1answer
2k 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
109 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
134 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 ...
9
votes
1answer
163 views

Generating Cartesian product of strings in R

Sometimes I need to create character vectors like this one: ...
5
votes
2answers
271 views

Binomial coefficient

I wrote a C++ function to calculate the binomial coefficient, trying to avoid overflows as much as possible. ...