Function Repository Resource:

FindAllPermutations

Source Notebook

Find all permutations of lists with non-unique elements

Contributed by: Nikolay Murzin

ResourceFunction["FindAllPermutations"][list]

returns a list of permutations that produces a list from its sorted version.

ResourceFunction["FindAllPermutations"][list1,list2]

returns a list of permutations that permutes list1 into list2.

Details

Permutations are returned as Cycles.

Examples

Basic Examples (2) 

Find all permutations that produce a list with non-unique elements from its sorted version:

In[1]:=
ResourceFunction["FindAllPermutations"][{3, 1, 1, 2}]
Out[1]=

Find all permutations that convert one list to another:

In[2]:=
ResourceFunction["FindAllPermutations"][{3, 1, 1, 2}, {3, 1, 2, 1}]
Out[2]=

Scope (1) 

If a list can't be permuted into a target list, an empty list is returned:

In[3]:=
ResourceFunction["FindAllPermutations"][{1, 2, 3}, {1, 2, 4}]
Out[3]=

Properties and Relations (2) 

FindPermutation only finds one permutation:

In[4]:=
FindPermutation[{3, 1, 2, 1}]
Out[4]=

FindAllPermutations finds all possible permutations:

In[5]:=
ResourceFunction["FindAllPermutations"][{c, a, b, a}]
Out[5]=

Version History

  • 1.0.0 – 13 December 2021

Related Resources

License Information