Wolfram Research

Function Repository Resource:

ProgressiveMaxPositions

Source Notebook

Find the positions of the largest elements so far in a list

Contributed by: Stephen Wolfram

ResourceFunction["ProgressiveMaxPositions"][list]

gives the list of positions of the elements in list that are larger than any elements that appear before them.

Examples

Basic Examples

Find the positions of elements that are larger than any of the ones that came before:

In[1]:=
ResourceFunction[
 "ProgressiveMaxPositions"][{1, 1, 2, 5, 2, 2, 9, 1, 2, 11}]
Out[1]=

Applications

Find where progressively larger gaps between primes occur:

In[2]:=
ResourceFunction["ProgressiveMaxPositions"][
 Differences[Array[Prime, 10^4]]]
Out[2]=

Compute the position of the head over 50 steps of Turing machine evolution:

In[3]:=
hpos = TuringMachine[2506, {1, {{}, 0}}, 50][[All, 1, 3]]
Out[3]=

Find when the head is further to the right than ever before:

In[4]:=
ResourceFunction["ProgressiveMaxPositions"][hpos]
Out[4]=

Find when the head is further to the left:

In[5]:=
ResourceFunction["ProgressiveMaxPositions"][-hpos]
Out[5]=

Show the compressed evolution of the Turing machine:

In[6]:=
ArrayPlot[
 TuringMachine[2506, {1, {{}, 0}}, 50][[
  Union[ResourceFunction["ProgressiveMaxPositions"][hpos], ResourceFunction["ProgressiveMaxPositions"][-hpos]], 2]]]
Out[6]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Resource History

License Information