Questions tagged [permutation]

A permutation is an arrangement of objects into a particular order.

A permutation is an arrangement of objects into a particular order.

For example, permutations of a set such as {1,2,3} are (1,2,3), (1,3,2), (2,1,3), (2,3,1), (3,1,2), and (3,2,1). The number of permutation of n objects is n! = n*(n-1)*(n-2)*...*3*2*1

References

5231 questions
13
votes
4 answers

Regex to match all permutations of {1,2,3,4} without repetition

I am implementing the following problem in ruby. Here's the pattern that I want : 1234, 1324, 1432, 1423, 2341 and so on i.e. the digits in the four digit number should be between [1-4] and should also be non-repetitive. to make you understand in a…
Apoorv Saxena
  • 4,086
  • 10
  • 30
  • 46
13
votes
3 answers

Print out all permutations of an Array

I am working on a program, and I have a function that swaps the positions in an Array of length that is input by a user. However, I am trying to figure out how to print out this function call N! times, which would list all the permutations in the…
user4309460
13
votes
5 answers

number to unique permutation mapping of a sequence containing duplicates

I am looking for an algorithm that can map a number to a unique permutation of a sequence. I have found out about Lehmer codes and the factorial number system thanks to a similar question, Fast permutation -> number -> permutation mapping…
frnknstn
  • 7,087
  • 1
  • 17
  • 18
13
votes
2 answers

Generating inverse permutation

Suppose we are given a vector foo and we have to temporarily permute it (sort or re-order it), compute some vector bar on the base of it, and finally permute back both foo and bar to the original order of foo - that means inverse permutation: foo <-…
Ali
  • 9,440
  • 12
  • 62
  • 92
13
votes
2 answers

permutations/combinatorics library for java?

I am looking for a library for java that will generate all possible order permutations of a set. The only library I can find is combinatoricslib on google code. I find it very hard to believe this is the only java library that does this, and am…
Paul Sanwald
  • 10,899
  • 6
  • 44
  • 59
12
votes
9 answers

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…
Hallis
  • 159
  • 1
  • 6
12
votes
3 answers

Bitwise shift to generate all possible permutations in C

Possible Duplicate: Creating multiple numbers with certain number of bits set I'm attempting to write some code which will put each possible combination of numbers in an array by shifting the bits across. For example, I wanted to find all…
hungrii
  • 145
  • 1
  • 4
12
votes
1 answer

Algorithm for permutations of operators and operands

I came across this question on an interview website - We are given 4 numbers say n1, n2, n3, n4. We can place them in any order and we can use the mathematical operators +, -, *, / in between them to have the final result as 24. Write an…
Tushar Gupta
  • 1,410
  • 13
  • 22
12
votes
6 answers

Arbitrary number of nested-loops?

I'm looking to take an arbitrary number of lists (e.g. [2, 1, 4 . . .], [8, 3, ...], . . .) and pick numbers from each list in order to generate all permutations. E.g.: [2, 8, ...], [2, 3, ...], [1, 8, ...], [1, 3, ...], [4, 8, ...], [4, 3, ...], …
Nick L
  • 121
  • 1
  • 4
12
votes
6 answers

All Permutations of a String in Python (Recursive)

I need a kick in the head on this one. I have the following recursive function defined: def perms(s): if(len(s)==1): return s res = '' for x in xrange(len(s)): res += s[x] + perms(s[0:x] + s[x+1:len(s)]) return res +…
gnp210
  • 153
  • 1
  • 1
  • 9
12
votes
3 answers

How to get all combinations of a list?

I know that I can use itertools.permutation to get all permutations of size r. But, for itertools.permutation([1,2,3,4],3) it will return (1,2,3) as well as (1,3,2). I want to filter those repetitions (i.e obtain combinations) Is there a simple…
Bush
  • 2,433
  • 5
  • 34
  • 57
12
votes
3 answers

n-th or Arbitrary Combination of a Large Set

Say I have a set of numbers from [0, ....., 499]. Combinations are currently being generated sequentially using the C++ std::next_permutation. For reference, the size of each tuple I am pulling out is 3, so I am returning sequential results such as…
anon_dev1234
  • 2,143
  • 1
  • 17
  • 33
12
votes
4 answers

Finding the (lexicographic) index of a permutation of a given array.

Given an array say "bca", I need to find the number of permutations which are lexicographicaly greater than the given permutation. Thus, in this example, cab, cba are permutations which are greater. Thus the answer would be 2. I tried approaching…
user1628340
  • 901
  • 4
  • 14
  • 27
12
votes
3 answers

String permutations rank + data structure

The problem at hand is: Given a string. Tell its rank among all its permutations sorted lexicographically. The question can be attempted mathematically, but I was wondering if there was some other algorithmic method to calculate it ? Also if we…
Rndm
  • 6,710
  • 7
  • 39
  • 58
12
votes
5 answers

Excel vba to create every possible combination of a Range

I have a problem that I haven't been able to find anywhere on the web (it may be there, but I can't find it, heh). I have a spreadsheet with 13 columns of data. Each of the column contains variations of a parameter that needs to go into an overall…
Kelvin
  • 1,357
  • 2
  • 11
  • 22