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

learn more… | top users | synonyms

4
votes
2answers
44 views

Solver for Jumble puzzle

Here is my first attempt to solve Jumble puzzle: ...
4
votes
1answer
63 views

Password Attacker (Google apac test problem)

Original Problem Short Summary: Given a \$M\$ possible characters all of which must be used at least once, find the number of possible combinations of length (exactly) \$N\$. The ...
4
votes
5answers
137 views

Permutation of n lists

I have code which gives permutations for 10 lists. The code works fine for small number of lists with small number of values. Result : It should return all possible permutations. I have to store the ...
5
votes
1answer
384 views

Solving the 'Vietnamese school maths problem'

Having read Can you do the maths puzzle for Vietnamese eight-year-olds that has stumped parents and teachers?, which presented the problem of filling in numbers 1 to 9 to satisfy $$ a + 13 ...
0
votes
1answer
48 views

Unique combinations of sets with N min selections of overall set

I'm in the process of attempting to write a parser compiler. In this, sets play a major role. I'm in the 'lexical ambiguity' isolation phase, and to that, I need to yield a set of every possible ...
2
votes
1answer
60 views

Generating alphanumeric combinations

I was happy with my shell script that needed to generate alphanumeric combinations of length N (in this case, 3) for i in {a..z}{a..z}{a..z}; do ... Now I became ...
2
votes
1answer
29 views

Generating combinations of n elements in groups of k

I've written this program that writes all the combinations (without repetition) of n elements in groups of k. I think the code is good, but I like to know if you have some better (or faster) ...
4
votes
0answers
48 views

Looking for arithmetic operations that result in 24 [migrated]

I'm writing a program that evaluates the integer values of 4 playing cards (numbers 1-13), and displays a solution that equals 24. I have a large if statement that I've written for this and have ...
3
votes
1answer
45 views

Necklace counting problem-with consecutive prime constraint

This is codeEval challenge to count the number of chains possible to make with beads holding numbers. Constraint is sum of the consecutive beads of chain should be a prime number. The standard ...
3
votes
2answers
53 views

Permutation and combination calculator

I wanted to make something for the Community Challenge, so I made a simple permutation and combination calculator. I'd like input on: The overall design - any suboptimal choices that could be ...
3
votes
2answers
61 views

Printing all the permutations of a string in alphabetical order-ver1.1

I adapted most of the suggestions from answers for my previous question Printing all the permutations of a string in alphabetical order to rewrote my solution again. Please let me know any more ...
2
votes
2answers
117 views

Genetic algorithm for solving a puzzle (v. 2)

Thanks to your wonderful comments regarding the first version of my code, I have been able to improve it. This new version is more readable (I guess). The problem is that it seems to me that there is ...
8
votes
3answers
904 views

Genetic algorithm for solving a puzzle

Edit. Version 2. I am working on a genetic algorithm in order to solve a little "puzzle." Given a text file with N rows with 4 int each, the idea is to ...
2
votes
4answers
122 views

Printing all the permutations of a string in alphabetical order

It is a code eval challenge question https://www.codeeval.com/open_challenges/14/. My answer was accepted, and I modified my code again to improve it. Please let me know is it possible to improve it ...
4
votes
1answer
43 views

Calculate number of possible combinations to make $100 with all US denominations

I know that this could be made much more efficient, I am just not sure as to how. This program ignores the 100 dollar denomination to cut computation time in half and just starts ...
3
votes
3answers
69 views

Generating letter combinations

It's about two months since I posted this question on CodeReview. I've been working hard to improve the code posted there and came up with the following. ...
5
votes
2answers
109 views

Consecutive Primes challenge at CodeEval.com and memory allocation issue

I finally solved this challenge with using recursion and figured out why the automatic scorer wasn't passing my previous solutions. I was using NSMutableArray to ...
1
vote
1answer
114 views

Consecutive Primes challenge at CodeEval.com

I am working through a new challenge on CodeEval.com and I think I am getting a correct result but I can't get through their grader. I am not exactly sure where error is. I didn't post this on stack ...
2
votes
1answer
39 views

Fast canonical indexing of elements in array

Given two arrays of elements: aaabbccdefaa zzzccddafgzz I want to check whether these two arrays are equivalent up to a relabeling. My strategy is to map them into a canonical form and ...
3
votes
2answers
121 views

Is_permutation() on sequence containers in O(n) complexity

This question is a continuation of my previous question: Check is_permutation on a pair of same sized arrays. I improved the implementation to generalize for all sequence containers. Please let me ...
3
votes
1answer
54 views

Modified Coupon Collector's Problem in Java

What is Coupon Collector's Problem? In probability theory, the coupon collector's problem describes the "collect all coupons and win" contests. It asks the following question: Suppose that there ...
3
votes
2answers
71 views

Expected value (and distribution) of sum of six balls labeled 1-49, no replacement

This code finds expectation and standard deviation of sum(x) of 6 digited base-49 numbers with all digits distinct. The expectation is: \$\mu={\rm ...
3
votes
2answers
86 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
87 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
63 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
98 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
217 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
80 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, ...
1
vote
1answer
83 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
176 views

Pascal's triangle in PHP

Are there any optimization suggestions? ...
3
votes
0answers
58 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
48 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
41 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
87 views

Print all combinations

Question: ...
0
votes
2answers
93 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
160 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
60 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
66 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
107 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
466 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
46 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
604 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
194 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
251 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
161 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
69 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
80 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
72 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 ...
6
votes
3answers
264 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
824 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 ...