### Basic Examples

Basic Examples

Split a permutation given as a list into sublists starting at its left-to-right maximum:

@{2,4,1,6,7,5,3}

In[]:=

{{2},{4,1},{6},{7,5,3}}

Out[]=

The input does not have to be a permutation:

r1=RandomInteger[{1,7},20]

In[]:=

{1,4,2,6,4,2,3,3,3,4,5,3,2,4,5,6,7,5,2,5}

Out[]=

@r1

In[]:=

{{1},{4,2},{6,4,2,3,3,3,4,5,3,2,4,5,6},{7,5,2,5}}

Out[]=

Flatten to get back the original list:

r1==Flatten@%

In[]:=

True

Out[]=

### Scope

Scope

Here is a larger example:

p1=PermutationList@RandomPermutation@50

In[]:=

{26,10,11,24,33,48,44,6,15,40,34,12,20,5,41,46,45,8,25,1,36,29,49,35,22,21,30,43,13,47,9,39,19,23,3,42,32,18,28,16,50,17,38,7,2,37,14,27,31,4}

Out[]=

s1=

@p1

In[]:=

{{26,10,11,24},{33},{48,44,6,15,40,34,12,20,5,41,46,45,8,25,1,36,29},{49,35,22,21,30,43,13,47,9,39,19,23,3,42,32,18,28,16},{50,17,38,7,2,37,14,27,31,4}}

Out[]=

Each sublist starts from its maximum:

Row[ListLinePlot/@s1]

In[]:=

Out[]=

The first elements are increasing:

ListLinePlot[First/@s1]

In[]:=

Out[]=

The sublists of s1 can be thought of as cycle notation for the permutation, but with a different canonical form than the Wolfram Language default, where each sublist starts with its minimum :

Cycles[s1]

In[]:=

Cycles[{{1,6,49,43,9,3,41,32,13,14,33,8,10,40,7,19,17,50,44,4,31,47,20,39,28,29,2,21,30},{11,27,46},{12,22,34,48,25,45,37,16,15,35,42},{36,38}}]

Out[]=