cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

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.

This page as a plain text file.
%I A358402 #22 Jan 22 2023 02:35:37
%S A358402 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,
%T A358402 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,
%U A358402 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
%N 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.
%C A358402 This sequence can be considered a variation of Van Eck's sequence, see A181391, but where the sequence forms a loop of numbers, joined at its first and last term before each a(n) is calculated. When a previously unseen number first appears the following term is 0, and as 0 appears as the first term of the sequence, the next term after these 0's will always be 1.
%C A358402 See A358403 for the index where each number first appears.
%H A358402 Michael De Vlieger, <a href="/A358402/b358402.txt">Table of n, a(n) for n = 1..16384</a>
%H A358402 Brady Haran and N. J. A. Sloane, <a href="https://www.youtube.com/watch?v=etMJxB-igrc">Don't Know (the Van Eck Sequence)</a>, Numberphile video (2019).
%e A358402 a(5) = 1 as a(4) = 0 and 0 appears as the first term of the sequence.
%e A358402 a(6) = 2 as a(5) = 1 and a(3) = 1, these being separated by two terms.
%e A358402 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.
%t A358402 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 *)
%o A358402 (Python)
%o A358402 from itertools import count, islice
%o A358402 def agen():
%o A358402     an, first, prev = 0, {0: 1}, {0: 1}
%o A358402     for n in count(2):
%o A358402         yield an
%o A358402         an1 = 0 if first[an] == n-1 else min(n-1-prev[an], first[an])
%o A358402         if an1 not in first: first[an1] = prev[an1] = n
%o A358402         prev[an] = n-1
%o A358402         an = an1
%o A358402 print(list(islice(agen(), 96))) # _Michael S. Branicky_, Nov 14 2022
%Y A358402 Cf. A181391, A358403, A358405, A358406, A171862, A171863.
%K A358402 nonn
%O A358402 1,6
%A A358402 _Scott R. Shannon_, Nov 14 2022