Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Construct a list of permutations so that successive permutations differ by exactly one transposition
ResourceFunction["SwapOrderedPermutations"][l] constructs all permutations of list l such that adjacent permutations differ by only one transposition. |
Compute a full list of permutations each differing from the previous permutation by exactly one transposition:
In[1]:= |
|
Out[1]= |
|
Find swap-ordered permutations for four elements:
In[2]:= |
|
Out[2]= |
|
SwapOrderedPermutations differs from Permutations in the ordering of the result:
In[3]:= |
|
Out[3]= |
|
In[4]:= |
|
Out[4]= |
|
In[5]:= |
|
Out[5]= |
|
SwapOrderedPermutations defines a Hamiltonian path in the transposition graph:
In[6]:= |
|
Out[6]= |
|
This work is licensed under a Creative Commons Attribution 4.0 International License