Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Split a list at its left-to-right maxima
ResourceFunction["DescendingSublists"][list] makes sublists of list starting at its left-to-right maxima. |
Split a permutation given as a list into sublists starting at its left-to-right maximum:
In[1]:= | ![]() |
Out[1]= | ![]() |
The input does not have to be a permutation:
In[2]:= | ![]() |
Out[2]= | ![]() |
In[3]:= | ![]() |
Out[3]= | ![]() |
Flatten to get back the original list:
In[4]:= | ![]() |
Out[4]= | ![]() |
Here is a larger example:
In[5]:= | ![]() |
Out[5]= | ![]() |
In[6]:= | ![]() |
Out[6]= | ![]() |
Each sublist starts from its maximum:
In[7]:= | ![]() |
Out[7]= | ![]() |
The first elements are increasing:
In[8]:= | ![]() |
Out[8]= | ![]() |
The sublists of s1 an 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:
In[9]:= | ![]() |
Out[9]= | ![]() |
This work is licensed under a Creative Commons Attribution 4.0 International License