Questions tagged [permutation]
For questions about the functionality related to permutations in Mathematica.
56
questions
13
votes
3
answers
2k
views
How to represent a list as a cycle
I want to select distinct cycles (represented by List).
The cycle {a, b, c, d} must be the same as {b, c, d, a} or ...
25
votes
7
answers
2k
views
Permutations[Range[12]] produces an error instead of a list
This input:
Permutations[Range[12]]
Results in this (error) output:
...
15
votes
3
answers
918
views
Find all permutations with a condition
How can I find all the permutations of {a, b, c} where a + b + c = n?
For instance: if n = 3...
34
votes
9
answers
2k
views
Faster derangements?
I wonder what is the fastest method to generate derangements?
Both the Combinatorica function and Martin Ender's answer to Permutations of lists of fixed even numbers are based on filtering the ...
21
votes
4
answers
1k
views
Optimization of function taking a permutation
I have a function $f$ which takes a permutation $P$ of the integers 1-100 in order to give a numerical value $f(x)$. The function is given by a black box, but is relatively "smooth", so should be ...
16
votes
1
answer
527
views
ls Ordering[Ordering[list]] optimal?
Given a list list with unique elements, the task is to replace each element by its position in Sort[list]. For example,
...
13
votes
4
answers
575
views
Equivalent Nested Loop Structure (combinations_with_replacement)
Consider the following examples:
...
14
votes
4
answers
5k
views
How to remove repeated permutations?
I want to get the Permutations on the elements of a list. Then I'm doing this:
...
0
votes
1
answer
348
views
Set conditions at a permutation
I need to find all permutations of 3 elements from {a,b,c,d,e} with this condition: These must include element d maximum once, ...
17
votes
12
answers
4k
views
Fastest way to generate {{a,a},{a,b},{a,c},{b,b},{b,c},{c,c}} from {a,b,c}
What is the fastest way to generate {{a,a},{a,b},{a,c},{b,b},{b,c},{c,c}} from l={a,b,c}? I've tried
...
6
votes
2
answers
311
views
Challenge: Creating Compilable Permutations Function
As Mathematica's implemented Permutations function is not compilable, I tried to write my very own Permutations implementation, ...
5
votes
4
answers
492
views
Sort two lists at the same time, based on another
I am new to using Mathematica and I can not find a solution to what I am wanting to do.
I want to take a list such as:
x = {1,2,3,4,5,6,7,8}
and a second list (...
22
votes
3
answers
2k
views
Generating Tuples with restrictions
I am interested in a certain subset of all tuples. Generating all with Tuples and then filtering is wasteful, and will "blow up" very quickly.
For a concrete ...
14
votes
2
answers
1k
views
What is the fastest way to get the nth distinct permutation of a list?
What is the fastest way to write a function nthPermutation[xs_List, n_Integer] which is equivalent to Permutations[xs][[n]] but ...
14
votes
1
answer
4k
views
How to apply a permutation to a symmetric square matrix?
Given a symmetric square matrix, how can I apply a permutation to the rows and columns (i.e. the same permutation to both the rows and the columns) such a way that the new structure of the matrix ...