combinatorics

Channel allocation algorithm

We have a set of radio nodes in close proximity to each other and would like to allocate the frequencies for them to minimize overlap. To get complete coverage of the area, radio channels need to be oversubscribed and so we will have nearby radios transmitting on the same frequency. Sample data: 5 Frequencies 343 Radios 4158 Edges M...

Combinatorics : Grouping Characters Challenges

I was working on some grouping problems at my work. There are quite a few questions, please bear with me. I find them quite interesting. If anyone here is also interested in combinatorics, please help me out. Ok so we have a bunch of characters , here i have taken a i d s. What are the ways we can group the elements ? Let us say we ha...

How to produce the i-th combination/permutation without iterating

Given any iterable, for example: "ABCDEF" Treating it almost like a numeral system as such: A B C D E F AA AB AC AD AE AF BA BB BC .... FF AAA AAB .... How would I go about finding the ith member in this list? Efficiently, not by counting up through all of them. I want to find the billionth (for example) member in this list. I'm tr...

Unique permutations with no mirrored or circular repetitions

Some background: I'm writing a more or less brute force search algorithm for solving a problem that I have. In order to do this, I need to generate and evaluate all possibilities to find out which is best. Since the evaluation actually takes some time I would prefer to generate as little as possible solutions that completely cover my sea...

Number of combinations in configurator

I have been asked to program a routine to decide the number of possible combinations in a product configurator. The configurator is really simple. Even though it has more features than this, it can be modeled as several "radio groups" (like the UI control) where one of n options has to be selected. The only kind of constraints that can...

Combinitorics Counting Puzzle: Roll 20, 8-sided dice, what is the probability of getting at least 5 dice of the same value

Assume a game in which one rolls 20, 8-sided die, for a total number of 8^20 possible outcomes. To calculate the probability of a particular event occurring, we divide the number of ways that event can occur by 8^20. One can calculate the number of ways to get exactly 5 dice of the value 3. (20 choose 5) gives us the number of orders o...

Code-golf: generate pascal's triangle

Generate a list of lists (or print, I don't mind) a Pascal's Triangle of size N with the least lines of code possible! Here goes my attempt (118 characters in python 2.6 using a trick): c,z,k=locals,[0],'_[1]' p=lambda n:[len(c()[k])and map(sum,zip(z+c()[k][-1],c()[k][-1]+z))or[1]for _ in range(n)] Explanation: the first element of...

Generating random 6-character strings

How many possible words of length 6 can I generate from the English lower case alphabet, if each word starts with a random consonant, and after that vowels and consonants alternate? What if I add digits to my alphabet? See also this question. ...

Paths in complete graph

I have a friend that needs to compute the following: In the complete graph Kn (k<=13), there are k*(k-1)/2 edges. Each edge can be directed in 2 ways, hence 2^[(k*(k-1))/2] different cases. She needs to compute P[A !-> B && C !-> D] - P[A !-> B]*P[C !-> D] X !-> Y means "there is no path from X to Y", and P[ ] is the probability. So ...

Combinatorics with repeated chars on initial group

I know that if I have the following group of numbers { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } I can have 5040 different 4-digit numbers, using 10! / (10 - 4)! But if I repeat one number on the initial group, like { 1, 1, 2, 3, 4, 5, 6, 7, 8, 9 } How many different 4-digit numbers can we build ? I know the answer is 3360, just don't know h...

Combinatorics: Building 10 groups of 100 elements while elements remain sorted

Hello! I've got a problem concerning combinatorics. Unfortunately, I can't describe it abstractly so I try to explain it as a story. :) Problem: There are 100 children on the schoolyard. They all have unique heights, assuming the values are 100-199cm. You want to build 10 groups, each consisting of 1-99 children. How can you build al...

Whats the name of this game?

This is not a programming question per se, although the ultimate goal is to devise an algorithm. I'm looking for references or at least the name of a type of game. It is pretty widespread on television game-shows. The game is as follows: You have a number of slots, each slot contains an item (from some finite set), which you don't kno...

PHP: Caching ordered integer partition algorithm

Hello! First: The problem's name in Wikipedia is "ordered partition of a set". I have an algorithm which counts possible partitions. To speed it up, I use a cache: function partition($intervalSize, $pieces) { // special case of integer partitions: ordered integer partitions // in Wikipedia it is: ordered partition of a set global $...

Optimizing cartesian requests with affine costs

Hello, I have a cost optimization request that I don't know how if there is literature on. It is a bit hard to explain, so I apologize in advance for the length of the question. There is a server I am accessing that works this way: a request is made on records (r1, ...rn) and fields (f1, ...fp) you can only request the Cartesian prod...

random and unique subsets generation

Lets say we have numbers from 1 to 25 and we have to choose sets of 15 numbers. The possible sets are, if i'm right 3268760. Of those 3268760 options, you have to generate say 100000 What would be the best way to generate 100000 unique and random of that subsets? Is there a way, an algorithm to do that? If not, what would be the bes...

get every combination of strings

I had a combinatorics assignment that involved getting every word with length less than or equal to 6 from a specific combination of strings. In this case, it was S = { 'a', 'ab', 'ba' }. The professor just started listing them off, but I thought it would be easier solved with a program. The only problem is that I can't get a good alg...

Fast permutation -> number -> permutation mapping algorithms

I have n elements. For the sake of an example, let's say, 7 elements, 1234567. I know there are 7! = 5040 permutations possible of these 7 elements. I want a fast algorithm comprising two functions: f(number) maps a number between 0 and 5039 to a unique permutation, and f'(permutation) maps the permutation back to the number that it...

Set Combinatorics Algorithm in Java

I have a data set with attributes like this: Marital_status = {M,S,W,D} IsBlind = {Y,N} IsDisabled = {Y,N} IsVetaran = {Y,N} etc. There are about 200 such variables. I need an algorithm to generate combinations of the attributes, with one value at a time. In other words, my first combination would be: Marital_status = M, IsBlind = ...

How to generate a list of subsets with restrictions?

I am trying to figure out an efficient algorithm to take a list of items and generate all unique subsets that result from splitting the list into exactly 2 sublists. I'm sure there is a general purpose way to do this, but I'm interested in a specific case. My list will be sorted, and there can be duplicate items. Some examples: Inpu...

An algorithm for splitting a sequence in equally spaced, non colliding subsequences.

Hi to all, I got this problem that I can't just solve algorithmically. Let's say i have a video capture that always captures video frames at a fixed rate F (let's say 30 frames per second). What I want is to "split" this frame sequence in n (say four) subsequences. Each subsequence has its framerate fn, that's obviously < F. Frames in ...