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
2
votes
2 answers

How can I convert a combination function to permutation function?

I'm working on a separate program which has a bunch of gui, so I made a simpler program in an attempt to ask for help. I don't really know permutations and combinations that well. Anyway, I have a piece of code here which solves this function: F…
munchschair
  • 1,593
  • 3
  • 19
  • 43
2
votes
1 answer

k permutation in c++

I am trying to generate all k permutations of n values without repetition. For example, the permutations of 2 values from 3: 1, 2, 3 The answer is: 1, 2 1, 3 2, 1 2, 3 3, 1 3, 2 I am currently using next_permutation() from STL that generates all…
Maryam
  • 45
  • 7
2
votes
4 answers

finding nth combination (incremental approach) of letters (list)

What is the Pythonic way of finding the nth combination given a list of alphabets? # a = list("abc") Expected output (compinations): # a, b, c, aa, ab, ac, ba, bb, bc, ca, cb, cc, aaa, aab, aac, and so on... (until the nth)
2
votes
1 answer

Selecting optimal combinations

I have a problem that I am currently solving via brute force, but am looking for a more elegant solution. I have a system that runs various functions across multiple nodes. Each function is defined by a 'role'. Each 'role' can be defined to be…
2
votes
3 answers

How to generate the keys of a dictionary using permutations

I need to create a dictionary, values could be left blank or zero but i need the keys to be all the possible combinations of ABCD characters with lenght k. For example, for k = 8 lex = defaultdict(int) lex =…
Christos Karapapas
  • 1,018
  • 3
  • 19
  • 40
2
votes
2 answers

Perform a random permutation on an array in C++

I have one int* array and I want to perform a random permutation to this array. The function is similar with randperm in MATLAB. For example, I have an array int* A=[0 1 1 0] and if I call randperm(A,sizeof A) then one possible output would be A=[1…
Jame
  • 3,746
  • 6
  • 52
  • 101
2
votes
2 answers

in prolog, how to remove permutations of a list from a list of lists

Suppose I have a list of lists L= [[1,2,3], [3,2,1],[2,1,2],[3,1,2], [1,2,2]]. as you can see, [1,2,3],[3,2,1] and [3,1,2] are permutations of each other. [2,1,2] and [1,2,2] are also permutations of each other. My goal is to remove all…
2
votes
7 answers

Generating unique strings from a string of 1's, 0's, and ?'s (question marks)

Recently, I was asked to devise a function that would take a single string containing any of 1's, 0's, and ?'s (ex: "10?10?1", "00???11", "????", etc) as an input, and return a list of strings containing all the unique one-zero permutations of the…
user2113102
2
votes
2 answers

Permutations function in Matlab

In Wolfram Mathematica,there is a function called Permutations(http://reference.wolfram.com/mathematica/ref/Permutations.html). It can gives all permutations containing exactly n elements. For example: Permutations[{1,2,3,4}, {2}] gives {{1, 2},…
matrix42
  • 289
  • 1
  • 2
  • 12
2
votes
3 answers

Counting number of ways to select unique elements from list of lists

I'm having trouble with SPOJ Problem 423: Assignments. The problem asks me to count the number of possible assignments for n unique topics to n unique students so that each student gets exactly one topic that he/she likes. I have come up with a way…
Shashank
  • 13,713
  • 5
  • 37
  • 63
2
votes
1 answer

Python Itertools Permutations

I am currently writing a program that uses itertools, and one piece of it does not seems to functioning properly. I would like the input that determines the length of the lists the permutation function outputs to be equal to length of the list from…
5813
  • 1,073
  • 3
  • 14
  • 28
2
votes
1 answer

Why is my concatenation messing up when I pass in an array?

I wrote a method to permute an array (I realize Ruby comes with a permutation function, but I wanted to practice algorithms). I'm encountering a really weird error and have no idea why this is happening. Here's my code: def permute(arr) …
bioball
  • 1,339
  • 1
  • 12
  • 23
2
votes
2 answers

Time complexity of this code to list all permutations?

For example, if the input string is “ABC”, then output should be “ABC, ACB, BAC, BCA, CAB, CBA”. Here is my approach : #include #include #include void print(char str[],int visited[],int index,char temp[],int len) { …
nikola
  • 115
  • 1
  • 9
2
votes
2 answers

Finding all combinations from sets of possibilities

I have multiple sets of arrays that contain additional arrays that have values attached that I use for figuring out math. In order to find the best combination of these things, I need to mix and match from these arrays. I've seen "solutions" similar…
Wildcolt
  • 23
  • 3
2
votes
1 answer

Java - permutations of an array's elements - clearly explained

I've got an array of integers and need to find all the possible permutations of those elements using Java. So I'll have an array at the end that contains arrays, where each one is a permutation of the original single array. It must work with any…
Amoeba
  • 1,573
  • 4
  • 19
  • 25
1 2 3
99
100