OFFSET
1,5
COMMENTS
Conjecture: every positive integer eventually appears in the sequence.
Conjecture: The longest run of same, consecutive a(n) is 4 terms.
A003056 can be generated using the same rules but starting with 0.
LINKS
Michael De Vlieger, Table of n, a(n) for n = 1..10000
Michael De Vlieger, Log-log scatterplot of a(n), n = 1..2^16, showing records in red, first entries of other m in green, and the latest entries of m in blue.
Neal Gersh Tolunsky, Illustration of first 100 terms
EXAMPLE
For n=9, a(9) is the number of times a(9 - 1 - a(9-1)) = a(8 - a(8)) = a(3) = 1 has appeared in the sequence, so a(9)=5.
MATHEMATICA
nn = 2^20; c[_] = 0; a[1] = c[0] = c[1] = 1; a[2] = j = 0; Do[k = c[a[n - j - 1]]; a[n] = j = k; c[k]++, {n, 3, nn}]; Array[a, nn] (* Michael De Vlieger, Jun 25 2022 *)
PROG
(MATLAB) function a = A354971( max_n )
a = [1 0]; c = zeros(1, max_n); c(1:2) = [1 1];
for n = 3:max_n
m = a(n-1-a(n-1))+1;
a = [a c(m)];
c(c(m)+1) = c(c(m)+1)+1;
end
end % Thomas Scheuerle, Jun 15 2022
(PARI) { nb = [0]; for (n=1, #a=vector(81), print1 (a[n] = if (n==1, 1, n==2, 0, nb[1+a[n-1-a[n-1]]])", "); if (#nb < 1+a[n], nb = concat(nb, vector(#nb))); nb[1+a[n]]++) } \\ Rémy Sigrist, Jun 18 2022
(Python)
from collections import Counter
from itertools import count, islice
def agen():
a = [None, 1, 0]; inventory = Counter(a); yield from a[1:]
for n in count(3):
c = inventory[a[n-1-a[n-1]]]
a.append(c); inventory.update([c]); yield c
print(list(islice(agen(), 81))) # Michael S. Branicky, Jun 18 2022
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Neal Gersh Tolunsky, Jun 14 2022
STATUS
approved