permutation

How do you associate each Collection's item to another one's?

I have two Collection objects, I want to associate each object of these two in a readable way (HashMap, Object created on purpose, you choose). I was thinking of two loops one nested into the other, but maybe it's a well known problem and has a commonly understandable solution... What if the number of Collection objects raises above tw...

combination question

Hi Guys i have an array like below int[] array = new array[n];// n may be 2,3,4 example for N = 4 int[] array = new array[4]; array[0] = 2; array[1] = 4; array[2] = 6; array[3] = 8; how i calculate all unrepeated combination of this array without using linq may be within? 2,4,6,8 2,4,8,6 2,8,6,4 2,6,4,6 8,6,4,2 2,4,6,8 ....... ...

Fixed Place Permutation/Combination

I am looking for a way where I can generated different combination of 4 sets elements in such a manner that every set's element has a fixed place in the final combination: To explain better my requirement let me give sample of those 4 sets and finally what I am looking for: Set#1(Street Pre Direction) { N, S } Set#2(Street Name) {Frankf...

Speed dating algorithm

I work in a consulting organization and am most of the time at customer locations. Because of that I rarely meet my colleagues. To get to know each other better we are going to arrange a dinner party. There will be many small tables so people can have a chat. In order to talk to as many different people as possible during the party, ever...

SQL query--String Permutations

I am trying to create a query using a db on OpenOffice where a string is entered in the query, and all permutations of the string are searched in the database and the matches are displayed. My database has fields for a word and its definition, so if I am looking for GOOD I will get its definition as well as the definition for DOG. ...

Find the permutations where no element stays in place

I'm working with permutations where each element is different from its original location. I would like an algorithm that given {an input length, row and digit}, will give me the output number. Here's an example: If the input length is four, then all the permutations of 0123 are: 0123,0132,0213,0231,0312,0321, 1023,1032,1203,1230,1302...

Looking for elegant glob-like DNA string expansion

Hello, I'm trying to make a glob-like expansion of a set of DNA strings that have multiple possible bases. The base of my DNA strings contains the letters A, C, G, and T. However, I can have special characters like M which could be an A or a C. For example, say I have the string: ATMM I would like to take this string as input and o...

What would be the smartest way of running permutational code sequences to run via enumerator?

I have the following enum ( pseudo code ) enum RunSequence : int { ABCD = 1 , BCDA = 2 , DABC = 3 , .... } You get the idea ... Now if each letter represents some 4 lines of code , what would be the smartest way of building the logic for running those 16 lines of code in the desired sequence according to the RunSequence passed ...

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...

Is there C++ class that implements operations with permutations?

Is there C++ template class that implements operations with permutations and permutation group? Such class has to implement finding product and inverse, multiplication, etc. ...

Creating a game schedule with PHP _ Harder than I thought

I have an array of an unknown length which will always have an evenly divisible amount of values, for example: print_r($initialarray); Array ( [0] => 30 [1] => 31 [2] => 32 [3] => 33 [4] => 34 [5] => 35 ) I need to create sets: Set 1: 30 v 35; 31 v 34; 32 v 33; Set 2: 30 v 34; 31 v 33; 32 v 35; Set 3: 30 v 33; 31 v 32; 34 v 3...

Calculating permutations using a Java annotation

I'm interested in calculating permutations for parameters for something like this: public class Movie() { @Selection(minimum=1,maximum=10) public Integer setLength() {} @Selection(minimum=1.1,maximum=5.5) public Double setCost() {} } So I can write something like List getPermutations(); so that I could get a list of eve...

algorithm that will take numbers or words and find all possible combinations

I am looking for an algorithm that will take numbers or words and find all possible variations of them together and also let me define how many values to look for together. Example lets say the string or array is: cat dog fish then the results for a value of 2 could be: cat dog cat fish dog cat dog fish fish cat fish dog SO the r...

Finding a set of permutations, with a constraint

I have a set of N^2 numbers and N bins. Each bin is supposed to have N numbers from the set assigned to it. The problem I am facing is finding a set of distributions that map the numbers to the bins, satisfying the constraint, that each pair of numbers can share the same bin only once. A distribution can nicely be represented by an NxN ...

i can't figure out the bug in my program for calculating permutations

#include<stdio.h> #include<conio.h> main() { int i,j,k,x,y,n=4,a[]={1,2,3,4}; //n is the length of the array for(i=0;i<n;i++) { for(k=0;k<(n-2);k++) { for(j=(n-1-k);j>=1;j--) { y=a[j]; a[j]=a[j-1]; a[j-1]=y; for(x=0;x<n;x++) { printf("%d",a[x]); } printf("\t"); }...

Algorithm to permute elements in Array

Consider the following scenario. I have an array of numbers: [ 1,2,3,4 ] If this array was joined i would have the number 1234. I want to swap the numbers around to achieve the clossest higher number. 1234 will become 1243, which will become 1324, which will become 1342 and so forth.. What algorithm would i need use to make this...

Capitalization Permutations

I wanted to write a snippet of ruby that would take a string and output all possible permutations of capitalizations. Basically, I have a password that I remember, but I don't remember how it is capitalized. I have the following so far: def permute(str) perms = Array.new (2 ** str.size).times { perms << str } perms.each_index d...

How does this "Lexographic order generation algorithm" work?

from Wikipedia: Lexicographical order generation For every number k, with 0 ≤ k < n!, the following algorithm generates the corresponding lexicographical permutation of the initial sequence sj, j = 1, ..., n: function permutation(k, s) { var int n:= length(s); factorial:= 1; for j= 2 to n- 1 { // compu...

Using JavaScript/jQuery to generate fixtures

I'm putting together a tool for a colleague which helps to create a nice fixture list. I got about 2/3 through the tool, collecting various data ... and then I hit a brick wall. It's less of a JavaScript problem and more of a maths/processing brainblock. Lets say I have 4 teams, and they all need to play each other at home and away. Usi...

How to permute array into a given order with O(1) auxiliary space?

How do I implement the following OrderElements function? char chars[] = {'a', 'b', 'c', 'd', 'e'}; int want_order[] = {2, 4, 3, 0, 1}; int length = 5; OrderElements(chars, want_order, length); // chars now contains: c, e, d, a, b It's easy when you can use linear extra space, but can it be done with only constant extra space, i.e., ...