A354971 a(1)=1, a(2)=0; for n > 2, a(n) is the number of times a(n - 1 - a(n-1)) has appeared in the sequence.
1, 0, 1, 1, 3, 1, 1, 5, 5, 5, 1, 3, 3, 3, 6, 3, 5, 5, 5, 5, 1, 7, 1, 1, 9, 5, 9, 8, 8, 9, 9, 1, 4, 2, 10, 4, 10, 4, 1, 3, 2, 11, 4, 11, 4, 2, 2, 5, 5, 2, 10, 5, 5, 12, 2, 12, 2, 7, 3, 2, 2, 7, 9, 2, 3, 3, 5, 3, 10, 10, 10, 10, 3, 7, 13, 4, 7, 7, 7, 7, 11
Offset: 1
Examples
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.
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
Programs
-
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
-
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 *)
-
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
Comments