OFFSET
1,5
COMMENTS
LINKS
Scott R. Shannon, Table of n, a(n) for n = 1..10000.
Scott R. Shannon, Image of the first 100000 terms.
Scott R. Shannon, Image of the first 1000000 terms.
Scott R. Shannon, Image of the first 10000000 terms.
EXAMPLE
a(5) = 2 as a(4) = 0 and a(2) = 0, these being separated by two terms.
a(8) = 5 as a(7) = 2 and 2 appears as the fifth term of the sequence. Note that the number of terms between the two previous occurrences of 2 is 7 - 5 = 2 which is smaller than 5, so 5 is chosen.
MATHEMATICA
nn = 120; q[_] = c[_] = 0; m = a[1] = 0; Do[If[c[#] == 0, k = 0; c[#] = q[#] = n - 1, k = Max[n - 1 - c[#], q[#]]; c[#] = n - 1] &[m]; a[n] = m = k; If[k == u, While[c[u] > 0, u++]], {n, 2, nn}]; Array[a, nn]
PROG
(Python)
from itertools import count, islice
def agen():
an, first, prev = 0, {0: 1}, {0: 1}
for n in count(2):
yield an
an1 = 0 if first[an] == n-1 else max(n-1-prev[an], first[an])
if an1 not in first: first[an1] = prev[an1] = n
prev[an] = n-1
an = an1
print(list(islice(agen(), 87))) # Michael S. Branicky, Nov 14 2022
CROSSREFS
KEYWORD
nonn,look
AUTHOR
Scott R. Shannon, Nov 14 2022
STATUS
approved