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.

A337835 a(1) = 0 and for n > 1, a(n+1) = k - a(n) where k is the number of terms equal to a(n) among the first n terms.

Original entry on oeis.org

0, 1, 0, 2, -1, 2, 0, 3, -2, 3, -1, 3, 0, 4, -3, 4, -2, 4, -1, 4, 0, 5, -4, 5, -3, 5, -2, 5, -1, 5, 0, 6, -5, 6, -4, 6, -3, 6, -2, 6, -1, 6, 0, 7, -6, 7, -5, 7, -4, 7, -3, 7, -2, 7, -1, 7, 0, 8, -7, 8, -6, 8, -5, 8, -4, 8, -3, 8, -2, 8, -1, 8, 0, 9, -8, 9, -7, 9, -6, 9, -5, 9, -4, 9, -3, 9
Offset: 1

Views

Author

Bence BernĂ¡th, Nov 17 2020

Keywords

Comments

Empirical observation: -A000194(n) <= a(n) <= A000194(n).

Examples

			For n = 4, a(4) = 2, which appeared only once in the sequence so a(5)=1-2=-1.
		

Crossrefs

Programs

  • MATLAB
    length=1000;
    sequence(1)=0;
    for n=2:1:length
            sequence(n)=nnz(sequence==sequence(end))-sequence(n-1);
    end
    
  • Mathematica
    a = {0}; Do[AppendTo[a, Count[a, a[[-1]]] - a[[-1]]], {100}]; a (* Amiram Eldar, Nov 18 2020 *)
    a[1] = 0; a[n_Integer?Positive] := a[n] = Count[Array[a, n - 1], a[n - 1]] - a[n - 1]; Array[a, 101] (* Jan Mangaldan, Nov 27 2020 *)
  • PARI
    lista(nn) = {my(va = vector(nn)); for (n=2, nn, va[n] = #select(x->(x==va[n-1]), vector(n-1, k, va[k])) - va[n-1];); va;} \\ Michel Marcus, Nov 18 2020
    
  • Python
    from itertools import islice
    from collections import Counter
    def agen(): # generator of terms
        an, k = 0, Counter()
        while True:
            yield an
            k[an] += 1
            an = k[an] - an
    print(list(islice(agen(), 86))) # Michael S. Branicky, Nov 12 2022