A329221 a(0)=0. If a(n)=k is the first occurrence of k then a(n+1)=a(k), otherwise a(n+1)=n-m where m is the index of the greatest prior term.
0, 0, 1, 0, 1, 2, 1, 1, 2, 3, 0, 1, 2, 3, 4, 1, 1, 2, 3, 4, 5, 2, 1, 2, 3, 4, 5, 6, 1, 1, 2, 3, 4, 5, 6, 7, 1, 1, 2, 3, 4, 5, 6, 7, 8, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 3, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 1, 1, 2, 3, 4, 5, 6, 7, 8
Offset: 0
Examples
a(0)=0 is the first occurrence of the term 0, therefore a(1)=a(0+1)=a(0)=0. a(1)=0 has been seen before, and 0 is the index of the greatest prior term (0), so a(2)=a(1+1)=1-0=1.
Links
- Michael De Vlieger, Table of n, a(n) for n = 0..10000
- Wikipedia, Fractal sequence
Programs
-
Mathematica
Block[{a, c, j, k, m, r, nn}, nn = 120; c[] := 0; a[0] = j = r = m = 0; Do[If[c[j] == 0, k = a[j], k = n - m - 1]; c[j]++; Set[{a[n], j}, {k, k}]; If[k > r, r = k; m = n], {n, nn}]; Array[a, nn + 1, 0] ] (* _Michael De Vlieger, Jun 30 2025 *)
Comments