%I #98 Nov 13 2022 02:04:07
%S 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,
%T 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,
%U -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
%N 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.
%C Empirical observation: -A000194(n) <= a(n) <= A000194(n).
%H Bence BernĂ¡th, <a href="/A337835/b337835.txt">Table of n, a(n) for n = 1..10000</a>
%e For n = 4, a(4) = 2, which appeared only once in the sequence so a(5)=1-2=-1.
%t a = {0}; Do[AppendTo[a, Count[a, a[[-1]]] - a[[-1]]], {100}]; a (* _Amiram Eldar_, Nov 18 2020 *)
%t 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 *)
%o (MATLAB)
%o length=1000;
%o sequence(1)=0;
%o for n=2:1:length
%o sequence(n)=nnz(sequence==sequence(end))-sequence(n-1);
%o end
%o (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
%o (Python)
%o from itertools import islice
%o from collections import Counter
%o def agen(): # generator of terms
%o an, k = 0, Counter()
%o while True:
%o yield an
%o k[an] += 1
%o an = k[an] - an
%o print(list(islice(agen(), 86))) # _Michael S. Branicky_, Nov 12 2022
%Y Cf. A000194, A329985.
%K sign,easy
%O 1,4
%A _Bence BernĂ¡th_, Nov 17 2020