Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Cycle the elements of a list to the left until a criterion is satisfied
ResourceFunction["RotateLeftUntil"][expr,crit] cycles the elements in expr positions to the left until the first element satisfies crit. | |
ResourceFunction["RotateLeftUntil"][expr,crit,n] cycles the elements in expr positions until crit has been satisfied n times. | |
ResourceFunction["RotateLeftUntil"][expr,crit,n,m] cycles the elements in expr positions until crit has been satisfied n times with at most m iterations. |
Put the element "e" in front:
In[1]:= |
Out[1]= |
Rotate until the fourth prime is in front:
In[2]:= |
Out[2]= |
Rotate until the first 5 is in front:
In[3]:= |
Out[3]= |
Rotate until a value greater than or equal to 4 has been seen three times:
In[4]:= |
Out[4]= |
Find the seventh occurrence of a value between 5 and 7, with a maximum of 100 iterations:
In[5]:= |
Out[5]= |
Rotate the letters until a capital letter is at the front:
In[6]:= |
Out[6]= |
If the condition is not fulfilled within a cycle, $Failed is returned:
In[9]:= |
Out[9]= |
For crit that change, more than n cycles might be needed:
In[10]:= |
Out[10]= |
Increase the maximum number of iterations:
In[11]:= |
Out[11]= |
This work is licensed under a Creative Commons Attribution 4.0 International License