OFFSET
1,2
COMMENTS
In other words, let a(1)=1, a(2)=2, and for any n >= 2, let v be the greatest value <= a(n) among the first n-1 terms; a(n+1) is the least d > 0 such that a(n-d) = v.
LINKS
Rémy Sigrist, Table of n, a(n) for n = 1..25000
EXAMPLE
We start with a(1) = 1 and a(2) = 2. 2 has not appeared before, so we search for the greatest valid integer less than 2, which in this case is 1. 1 last occurred at a(1), which is 1 term before, so a(3) = 1.
1 occurred 2 terms before, so a(4) = 2.
2 appeared at term a(2), which is 2 terms before, so a(5) = 2.
2 appeared most recently at term a(5), which is 1 term earlier, so a(6) = 1.
And so on.
PROG
(PARI) seq(n)={my(a=vector(n)); a[1]=1; a[2]=2; for(n=2, n-1, my(m=1); for(i=2, n-1, if(a[i] <= a[n] && a[i] >= a[m], m=i)); a[n+1]=n-m); a} \\ Andrew Howroyd, Oct 25 2019
CROSSREFS
KEYWORD
nonn
AUTHOR
Robin Powell, Oct 11 2019
STATUS
approved