Basic Examples (2)
Basic Examples
(2)
Split a permutation given as a list into sublists starting at its left-to-right maximum:
In[270]:=
Out[270]=
{{2},{4,1},{6},{7,5,3}}
———
The input does not have to be a permutation:
In[274]:=
r1=RandomInteger[{1,7},20]
Out[274]=
{1,4,2,6,4,2,3,3,3,4,5,3,2,4,5,6,7,5,2,5}
In[275]:=
Out[275]=
{{1},{4,2},{6,4,2,3,3,3,4,5,3,2,4,5,6},{7,5,2,5}}
Flatten to get back the original list:
In[276]:=
r1==Flatten@%
Out[276]=
True
Scope (4)
Scope
(4)