login
A353778
a(1)=1. If a(n) is a novel term (seen for first time), a(n+1) = number of prior terms a(j) > a(n), 1 <= j <= n-1. If a(n) is a repeat of a term last seen at a(m), m < n, then a(n+1) = n-m-1.
0
1, 0, 1, 1, 0, 2, 0, 1, 3, 0, 2, 4, 0, 2, 2, 0, 2, 1, 9, 0, 3, 11, 0, 2, 6, 2, 1, 8, 2, 2, 0, 7, 3, 11, 11, 0, 4, 24, 0, 2, 9, 21, 1, 15, 2, 4, 8, 18, 2, 3, 16, 3, 1, 9, 12, 5, 16, 5, 1, 5, 1, 1, 0, 23, 1, 2, 16, 9, 13, 8, 22, 2, 5, 12, 18, 26, 0, 13, 8, 8, 0
OFFSET
1,6
COMMENTS
a(n) <= n for all n, with equality when n=1. Similar to A328096 initially, because novel terms are all records to begin with, but diverges when non-record novel terms appear, which produce nonzero following terms.
EXAMPLE
a(1)=1 is a novel record term, hence a(2)=0. a(3)=1 because a(2)=0 is a novel (non-record) term and only one term, a(1), exceeds it.
a(25) is the first occurrence of 6, so a(26)=2 because two prior terms (9 and 11) are greater than 6.
a(37) is the second occurrence of 4, first seen at a(12), therefore a(38)=37-12-1=24.
MATHEMATICA
nn = 81; c[_] = -1; a[1] = c[1] = 1; s = {}; Do[m = LengthWhile[s, # > a[i - 1] &]; Set[k, If[c[#] == -1, m, i - c[#] - 1]] &@ a[i - 1]; Set[{a[i], c[a[i - 1]]}, {k, i}]; s = Insert[s, a[i - 1], 1 + m], {i, 2, nn}]; Array[a, nn] (* Michael De Vlieger, May 08 2022 *)
CROSSREFS
Cf. A328096.
Sequence in context: A366614 A128097 A328096 * A173662 A263406 A257230
KEYWORD
nonn
AUTHOR
STATUS
approved