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

"K-transformed" permutations

I have been banging my head against this problem for days, and searched exhaustively online for any hints on how to solve it. If you enjoy mathematically oriented programming problems, please take a look! Here is the problem (PDF courtesy of…
Tozar
  • 976
  • 9
  • 20
11
votes
13 answers

C# Permutation of an array of arraylists?

I have an ArrayList[] myList and I am trying to create a list of all the permutations of the values in the arrays. EXAMPLE: (all values are strings) myList[0] = { "1", "5", "3", "9" }; myList[1] = { "2", "3" }; myList[2] = { "93" }; The count of…
TaRDy
11
votes
10 answers

Permutation of String letters: How to remove repeated permutations?

Here is a standard function to print the permutations of characters of a string: void permute(char *a, int i, int n) { int j; if (i == n) printf("%s\n", a); else { for (j = i; j < n; j++) //check till end of string { …
Kumar Alok
  • 2,512
  • 8
  • 26
  • 36
11
votes
3 answers

How to iterate over all unique permutations of a sequence in Rust?

Given a list of values, such as vec![0, 0, 1, 2], I would like to create an iterator that generates all of its unique permutations. That is, [0, 0, 1, 2] [0, 0, 2, 1] [0, 1, 0, 2] [0, 1, 2, 0] [0, 2, 0, 1] [0, 2, 1, 0] [1, 0, 0, 2] [1, 0, 2, 0] [1,…
Christopher Rybicki
  • 369
  • 1
  • 2
  • 11
11
votes
5 answers

Unique combinations of a list of tuples

Given a list of 3-tuples, for example:[(1,2,3), (4,5,6), (7,8,9)] how would you compute all possible combinations and combinations of subsets? In this case the result should look like this: [ (1), (1,4), (1,5), (1,6), (1,7), (1,8), (1,9), (1,4,7),…
p4rch
  • 163
  • 8
11
votes
5 answers

Tips implementing permutation algorithm in Java

As part of a school project, I need to write a function that will take an integer N and return a two-dimensional array of every permutation of the array {0, 1, ..., N-1}. The declaration would look like public static int[][] permutations(int N). The…
Trevor Dixon
  • 23,216
  • 12
  • 72
  • 109
11
votes
3 answers

Algorithm to mix colours on 7 individual pieces of toy

I'm a woodworker trying to seek some math and algorithm help on the expertise here. I'm trying to make 28 sets of Tangram for gifting relatives, like this: DanielHolth + RobotE at nl:Wp [CC BY-SA 3.0…
Tianhe Hou
  • 111
  • 3
11
votes
7 answers

Generate all length-n permutations of True/False?

This problem came up while trying to write code for a truth-table generating function. How can I generate a list of lists of all length-n permutations of True and False? In other words, given a list of elements [True, False], how can I generate all…
Anonymous
  • 411
  • 1
  • 4
  • 14
11
votes
3 answers

Combinations and Permutations in F#

I've recently written the following combinations and permutations functions for an F# project, but I'm quite aware they're far from optimised. /// Rotates a list by one place forward. let rotate lst = List.tail lst @ [List.head lst] /// Gets…
Noldorin
  • 144,213
  • 56
  • 264
  • 302
11
votes
2 answers

Counting all permutations of a string (Cracking the Coding Interview, Chapter VI - Example 12)

In Gayle Laakman's book "Cracking the Coding Interview", chapter VI (Big O), example 12, the problem states that given the following Java code for computing a string's permutations, it is required to compute the code's complexity public static void…
Ahmed Ismail
  • 113
  • 1
  • 8
11
votes
5 answers

Combination of two lists while keeping the order

I'm trying to join two lists and output all possible combinations of the merged list that maintains the ordering of the original two lists. For example: list_1 = [9,8] list_2 = [2,1] #output combo= [9821,9281,2981,2918,2198,9218] where in each…
Philip C
  • 113
  • 1
  • 7
11
votes
5 answers

PHP Dart game calculation slow performance

I've made a class to calculate the throw outs based on a score. For example if the score is currently 140 the class returns a array with collection of possible throw outs: [10] => Array ( [0] => T18 [1] => T18 [2] => D16 …
Youri
  • 495
  • 1
  • 4
  • 18
11
votes
1 answer

how to use next_permutation

I'm trying to get an arrangement of tic tac toe boards. So I have the following code: // 5 turns for x if x goes first std::string moves = "xxxxxoooo"; do { std::cout << moves << std::endl; } while ( std::next_permutation(moves.begin(),…
user1508519
11
votes
6 answers

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…
Jordi
  • 5,846
  • 10
  • 40
  • 41
10
votes
8 answers

Select matrix rows that are permutations of a given vector

I have a matrix X: one two three four [1,] 1 3 2 4 [2,] 2 0 1 5 [3,] 3 2 1 4 [4,] 4 9 11 19 [5,] 4 3 2 1 I want to get a new matrix Y which only contains rows that are permutations of "1", "2", "3", "4".…
Ricardo
  • 103
  • 5