A358402 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 minimum of n-1-k and j, where a(j) is the first occurrence of m in the sequence.
0, 0, 1, 0, 1, 2, 0, 1, 3, 0, 1, 3, 3, 1, 3, 2, 6, 0, 1, 3, 5, 0, 1, 3, 4, 0, 1, 3, 4, 4, 1, 3, 4, 3, 2, 6, 17, 0, 1, 3, 6, 5, 21, 0, 1, 3, 6, 6, 1, 3, 4, 18, 0, 1, 3, 5, 14, 0, 1, 3, 5, 5, 1, 3, 4, 14, 9, 0, 1, 3, 6, 17, 35, 0, 1, 3, 6, 6, 1, 3, 4, 16, 0, 1, 3, 5, 21, 43, 0, 1, 3, 6, 14, 27, 0, 1
Offset: 1
Keywords
Examples
a(5) = 1 as a(4) = 0 and 0 appears as the first term of the sequence. a(6) = 2 as a(5) = 1 and a(3) = 1, these being separated by two terms. a(17) = 6 as a(16) = 2 and 2 appears as the sixth term of the sequence. Note that the number of terms between the two previous occurrences of 2 is 16 - 6 = 10 which is larger than 6, so 6 is chosen.
Links
- Michael De Vlieger, Table of n, a(n) for n = 1..16384
- Brady Haran and N. J. A. Sloane, Don't Know (the Van Eck Sequence), Numberphile video (2019).
Programs
-
Mathematica
nn = 120; q[] = c[] = 0; m = a[1] = 0; Do[If[c[#] == 0, k = 0; c[#] = q[#] = n - 1, k = Min[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] (* Michael De Vlieger, Jan 21 2023 *)
-
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 min(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(), 96))) # Michael S. Branicky, Nov 14 2022
Comments