OFFSET
1,4
COMMENTS
The graph of the sequence shows interesting, "Christmas tree"-like shapes.
LINKS
Bence Bernáth, Table of n, a(n) for n = 1..10000
EXAMPLE
For n = 4, a(4) = 2, which appeared only once before, so a(5)=(1-2)*(-1)^5 = 1.
MATHEMATICA
a = {0}; Do[AppendTo[a, (-1)^k*(Count[a, a[[-1]]] - a[[-1]])], {k, 0, 81}]; a (* Amiram Eldar, Nov 21 2020 *)
PROG
(MATLAB)
length=10000;
sequence(1)=0;
for n=2:1:length
sequence(n)=((nnz(sequence==sequence(end)))-(sequence(n-1)))*(-1)^n;
end
(PARI) { for (n=1, #a=vector(83), print1(a[n]=if (n==1, 0, k=sum(k=1, n-1, a[k]==a[n-1]); (k-a[n-1])*(-1)^n) ", ")) } \\ Rémy Sigrist, Nov 22 2020
(Python)
from itertools import islice
from collections import Counter
def agen(): # generator of terms
an, k, sign = 0, Counter(), -1
while True:
yield an
k[an] += 1
sign *= -1
an = (k[an] - an)*sign
print(list(islice(agen(), 83))) # Michael S. Branicky, Nov 12 2022
CROSSREFS
KEYWORD
sign,look
AUTHOR
Bence Bernáth, Nov 21 2020
STATUS
approved