login
a(1) = 0; for n > 1, let a(n-1) = m; if a(n-1) is the first occurrence of m then a(n) = 0, but if there is a k < n-1 with a(k) = m, a(n) is the maximum of n-1-k and j, where a(j) is the first occurrence of m in the sequence.
4

%I #25 Jan 21 2023 20:28:01

%S 0,0,1,0,2,0,2,5,0,3,0,2,5,8,0,4,0,2,6,0,3,11,0,3,10,0,3,10,25,0,4,16,

%T 0,3,10,25,29,0,5,26,0,3,10,25,29,37,0,6,29,37,46,0,5,14,0,3,14,54,0,

%U 4,29,37,46,51,0,6,19,0,3,13,0,3,10,30,0,4,16,45,0,4,16,32,0,4,16,32,82

%N a(1) = 0; for n > 1, let a(n-1) = m; if a(n-1) is the first occurrence of m then a(n) = 0, but if there is a k < n-1 with a(k) = m, a(n) is the maximum of n-1-k and j, where a(j) is the first occurrence of m in the sequence.

%C This sequence uses the same selection rules as A358402 but here the maximum of the two offsets is chosen for a(n). The terms form an unusual pattern for larger values of n; see the linked images.

%C See A358406 for the index where each number first appears.

%H Scott R. Shannon, <a href="/A358405/b358405.txt">Table of n, a(n) for n = 1..10000</a>.

%H Scott R. Shannon, <a href="/A358405/a358405.png">Image of the first 100000 terms</a>.

%H Scott R. Shannon, <a href="/A358405/a358405_1.png">Image of the first 1000000 terms</a>.

%H Scott R. Shannon, <a href="/A358405/a358405_2.png">Image of the first 10000000 terms</a>.

%e a(5) = 2 as a(4) = 0 and a(2) = 0, these being separated by two terms.

%e 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.

%t 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]

%o (Python)

%o from itertools import count, islice

%o def agen():

%o an, first, prev = 0, {0: 1}, {0: 1}

%o for n in count(2):

%o yield an

%o an1 = 0 if first[an] == n-1 else max(n-1-prev[an], first[an])

%o if an1 not in first: first[an1] = prev[an1] = n

%o prev[an] = n-1

%o an = an1

%o print(list(islice(agen(), 87))) # _Michael S. Branicky_, Nov 14 2022

%Y Cf. A358406, A181391, A358402, A358403, A171862, A171863.

%K nonn,look

%O 1,5

%A _Scott R. Shannon_, Nov 14 2022