Questions tagged [combinatorics]

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

Filter by
Sorted by
Tagged with
1
vote
1answer
3k views

Counting friends of friends of friends

Can you comment, review or suggest things for this? Maybe it should be broken into two methods? friends is a list of strings of ...
7
votes
1answer
150 views

Project Euler #62 + Java 8 streams

(Inspired by this question) The digits of the cube, 41063625 (3453), can be permuted to produce two other cubes: 56623104 (3843) and 66430125 (4053). In fact, 41063625 is the smallest ...
16
votes
2answers
337 views

Minimising the triangle

A triangle needs a good foundation. Every row in the triangle is derived from the sum of the two values below it. However, there can be no repeated values, if a value shows up more than once the ...
4
votes
5answers
773 views

Finding the smallest cube for which exactly five permutations of its digits are cube

(Project Euler #62) The digits of the cube, 41063625 (3453), can be permuted to produce two other cubes: 56623104 (3843) and 66430125 (4053). In fact, 41063625 is the smallest cube which ...
3
votes
2answers
3k views

All upper and lowercase permutations of a string

A couple of questions: Is the algorithm wasting CPU time or memory unnecessarily? If there is something in the code that is not idiomatic Python, how to improve on that? ...
3
votes
2answers
4k views

Permutations in C#

I have a program that will get all possible permutations of a certain equation: A + 13 * B / C + D + 12 * E - F - 11 + G * H / I - 10 == 66 Where A, B....I is a value 1-9, and where each digit is ...
3
votes
3answers
11k views

Letter combinations of phone dial pad number

In preparation for interviews, I have written a solution to this question: Given a sequence of numbers (34128) and an input map such as a dial pad on a phone (2->[a,b,c], 3->[d,e,f], 4->[g,h,i])...
5
votes
1answer
399 views

Safe cracker string with all combinations

Imagine a safe with a 4-digit code, and accepting a continuous stream of code entries, such that when the 4 digits are seen in the right sequence, the safe opens. Generate a short string that contains ...
4
votes
2answers
344 views

Solver for Jumble puzzle

Here is my first attempt to solve Jumble puzzle: ...
5
votes
1answer
509 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 first ...
4
votes
5answers
2k 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 ...
6
votes
1answer
726 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 \frac{b}{c}...
1
vote
2answers
111 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 ...
6
votes
2answers
175 views

Covering array scraper and sorter

A covering array is an \$N \times k\$ array in which each element is a from a set of \$v\$ symbols, and for every \$t\$ columns, every possible set of \$v^t\$ choices of the symbols appears at least ...
2
votes
1answer
149 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
85 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) ...
10
votes
2answers
383 views

Approximate (250 over 100) permutation best fitting certain criteria

Given a list of 250 words of 4 letters each, what is the fastest way, in Python, to find a subsample of 100 words (drawn without replacement) so that the distribution of letters across the whole ...
4
votes
1answer
1k 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
3k 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
166 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
185 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 ...
9
votes
3answers
2k 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
392 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
2k 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
2answers
162 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. ...
6
votes
2answers
2k 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
809 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 ...
3
votes
1answer
96 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 then ...
4
votes
2answers
233 views

Is_permutation() on sequence containers in O(n) complexity - follow-up

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 ...
4
votes
1answer
1k 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 is ...
5
votes
2answers
928 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 E[X]}=\frac1n\sum_{k=0}^{n}x_i=\frac{x_1+x_2+\...
3
votes
2answers
258 views

Project Euler 78: Counting Partitions

Project Euler problem 78: Let \$p(n)\$ represent the number of different ways in which \$n\$ coins can be separated into piles. For example, five coins can be separated into piles in exactly seven ...
4
votes
2answers
182 views

Check is_permutation on a pair of same sized arrays - follow-up

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 ...
3
votes
3answers
1k views

Check whether given a pair of arrays are permutation of each other

Does this implementation guarantee execution of \$O(n)\$ time? What is the additional space utilization for this implementation by excluding the original array size? Is it \$O(1)\$? ...
7
votes
2answers
1k 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 ...
3
votes
1answer
4k 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 ...
6
votes
2answers
618 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
592 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, ahmed,...
6
votes
1answer
5k 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, ...
2
votes
1answer
2k 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
5k views

Pascal's triangle in PHP

Are there any optimization suggestions? ...
8
votes
2answers
765 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 ...
1
vote
1answer
416 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 \$...
2
votes
1answer
1k 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
247 views

Print all combinations

Question: ...
0
votes
2answers
214 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
351 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
132 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
78 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, ...
16
votes
1answer
176 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 ...