Skip to main content

Questions tagged [permutation]

For questions about the functionality related to permutations in Mathematica.

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 ...
praaeew's user avatar
  • 153
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: ...
Harold's user avatar
  • 1,017
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...
Filippo Vitale's user avatar
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 ...
Mr.Wizard's user avatar
  • 272k
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 ...
SPPearce's user avatar
  • 5,673
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, ...
Roman's user avatar
  • 48.8k
13 votes
4 answers
575 views

Equivalent Nested Loop Structure (combinations_with_replacement)

Consider the following examples: ...
expression's user avatar
  • 5,662
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: ...
Red Banana's user avatar
  • 5,411
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, ...
Nasi Jofce's user avatar
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 ...
Thrash's user avatar
  • 415
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, ...
Wizard's user avatar
  • 2,720
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 (...
connor's user avatar
  • 143
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 ...
Kiro's user avatar
  • 1,521
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 ...
David Zhang's user avatar
  • 2,336
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 ...
István Zachar's user avatar

15 30 50 per page