permutation

Set combination question

Got this as an homework assignment and not really sure where to start! Given the set {1,2,3,4}, you can form six combinations of length two from that set, viz: {1,2},{1,3},{1,4},{2,3},{2,4},{3,4} If I was to choose one of the combinations, ({1,2} for example), how can I tell how many of the others are not disjoint to it? In this cas...

Generate all binary strings of length n with k bits set

What's the best algorithm to find all binary strings of length n that contain k bits set? For example, if n=4 and k=3, there are... 0111 1011 1101 1110 I need a good way to generate these given any n and any k so I'd prefer it to be done with strings. ...

Permutations for digits represented by Phone Number

Guys, I have an interview in 2 days and I am having a very hard time finding a solutions for this question: What I want to do is .. for any phone number .. the program should print out all the possible strings it represents. For eg.) A 2 in the number can be replaced by 'a' or 'b' or 'c', 3 by 'd' 'e' 'f' etc. In this way how many possi...

PHP Clean Up Permutated Array

Hey all, basically, i have an array: array('a', 'b', 'c'); Now i run it through an array permutation function and the result is: Array ( [0] => Array ( [0] => C ) [1] => Array ( [0] => B ) [2] => Array ( [0] => B [1] => C ) ...

Prolog syntax - using function results

Hi, I am trying to perform a sum operation on every result of : combination(0,_,[]). combination(K,L,[X|Xs]) :- K > 0, el(X,L,R), K1 is K-1, combination(K1,R,Xs). el(X,[X|L],L). el(X,[_|L],R) :- el(X,L,R). For example, the user will enter is_sum_equal_10 ([1,2,3,4,5,6,7]) and the result will be true if the sum of any of the permut...

generating Variations without repetitions / Permutations in java

I have to generate all variations without repetitions made of digits 0 - 9. Length of them could be from 1 to 10. I really don't know how to solve it, especially how to avoid repetitions. Example: length of variations: 4 random variations: 9856, 8753, 1243, 1234 etc. (but not 9985 - contains repetition) I would be really gratefu...

c++ m bits permutations of a number

Hi, I am searching for a function that get as an input a number x (assuming 15), number of bits d (4) and number of permutations m (2). The output of the function will be all the numbers that are m bit's permutations from the given number x at a d length bits. For the given numbers, (x = 15, d = 4 and m = 2) we get 6=\binom{4}{2}differ...

javascript: speedy Array.contains(otherArray) ?

I have an array of arrays. The inner array is 16 slots, each with a number, 0..15. A simple permutation. I want to check if any of the arrays contained in the outer array, have the same values as a test array (a permutation of 16 values). I can do this easily by something like so: var containsArray = function (outer, inner) { ...

Find all combinations of a given set of numbers

Hi, say I have a set of numbers '0', '1', '2', ..., '9'. I want to find all numbers that contain exactly one of each of the numbers in my set. The problem is: Before I start my program, I do not know how many numbers and which numbers my set will include. (For example, the set could include the numbers '1', '3' and '14'.) I searched t...

Are there any better methods to do permutation of string?

void permute(string elems, int mid, int end) { static int count; if (mid == end) { cout << ++count << " : " << elems << endl; return ; } else { for (int i = mid; i <= end; i++) { swap(elems, mid, i); permute(elems, mid + 1, end); swap(elems, mid, i); } } ...

Stepping through all permutations one swap at a time

Given a list of n distinct items, how can I step through each permutation of the items swapping just one pair of values at a time? (I assume it is possible, it certainly feels like it should be.) What I'm looking for is an iterator that yields the indices of the next pair of items to swap, such that if iterated n!-1 times it will step t...

Creating every possible value of a fixed size array

Hello, I am trying to make some very elementary thing that will cycle through every possible permutation of an array. Really this is being done in assembly, but I'll explain it in C. Basically, say we have an array uint8_t *data=malloc(10); I want to create an algorithm that will print every possible combination of the bytes in the ar...

Is there a .NET library that can do string permutations or string expansion?

What I'm looking for is some library or some code of classes that can be used to expand construction strings into variations and permutations. Something like the following (syntax is mine, may be different): construction string: [Ff]oo [Bbß]ar|F(oo|oe) output strings: Foo Bar foo Bar Foo bar foo bar Foo ßar foo ßar Foo F...

Number of possible outcomes for 2 numbers given that one number is greater than the other

I am trying to write an algorithm to calculate outcomes. But I need help with combinatorics. Suppose I have to choose 2 numbers from 1 to 10. From the fundamental rule of counting, in the absence of any restriction, the number of possible outcomes is 10 * 10 = 100. (10 possible outcomes in choosing the first number x 10 possible outcom...

permutation(orderings) of a string of words but separated by a comma in between

Hello Everyone... I'm having some difficulty having this code generate a number of permutations(orderings) on a string separated by commas ...I can do just a regular string and have the permutations work on just letters but it is a bit more difficult when doing it with words separated by the commas... To have the program recognize the ...

Permutation of an arraylist objects

Hello friends, I have an arraylist which contains some objects and i have to get permutation of that objects?How can i do that? Suppose MyList is an arraylist which contains 4 objects. ArrayList myList = new ArrayList(); myList.Add(1); myList.Add(2); myList.Add(3); myList.Add(4); so arraylist count is 4 so i want 4!=24 I want 24 per...

counting combinations and permutations efficiently

I have some code to count permutations and combinations, and I'm trying to make it work better for large numbers. I've found a better algorithm for permutations that avoids large intermediate results, but I still think I can do better for combinations. So far, I've put in a special case to reflect the symmetry of nCr, but I'd still lik...

Efficient method to retrieve all permutations of a tree structure

Edited for a larger tree, for more examples. I have a tree structure that I need to generate all of the possible permutations of, with some restrictions. Given a tree like this: A1----(B1, B2) \ \___(C1) \__(E1, E2) / - A2----(B3, B4) \ \ \ \ \__(D1) \ \_(F1, ...

how to generate permutations of array in python?

i have an array of 27 elements,and i don't want to generate all permutations of array (27!) i need 5000 randomly choosed permutations,any tip will be useful... ...

C++ algorithm for N! orderings

I have a list of N items and I am wondering how I can loop through the list to get every combination. There are no doubles, so I need to get all N! orderings. Extra memory is no problem, I'm trying to think of the simplest algorithm but I'm having trouble. ...