OFFSET
0,6
COMMENTS
An inductive argument shows that a(n) <= n for all n, with equality iff n = 0. It follows that a(n) is well defined, and the sequence is infinite.
Apart from a(1) = 0 every repeat term is followed by a novel term, and vice versa.
Every nonnegative integer appears infinitely many times.
The proper subsequence given by a(2*k) for k >= 2 is the sequence itself, which is therefore fractal.
Starting from a(1) = 0 the sequence is the nonnegative integers interleaved with itself.
LINKS
Winston de Greef, Table of n, a(n) for n = 0..10000
Rémy Sigrist, C program
FORMULA
a(2*n + 1) = n for all n >= 0.
A027383(n) = 0. (n >= 0) gives the positions of all zeros after a(0) = 0.
a((2*k + 3)*2^n - 2)) = k (n >= 0) gives the positions of all k > 0.
The number of nonnegative terms occurring between consecutive zeros is 0,0,1,1,3,3,7,7,15,15,... (A000225(n), repeat).
a(n) = A101279(n+2) - 1. - Rémy Sigrist, Feb 18 2023
EXAMPLE
a(0) = 0 is a novel term so a(1) = a(a(0)) = 0. Since a(1) is a repeat term a(2) = 0 - a(0) = 0 - 0 = 0. a(1,2) = 0,0 is the only case of consecutive repeat terms.
Since a(2) = 0 is a repeat term, a(3) = 1 - a(1) = 1 - 0 = 1, a novel term so a(4) = a(a(1)) = 0, and so on.
a(16) = 3, a repeat term (last seen at a(7)), so a(17) = 15 - a(15) = 15 - 7 = 8.
MATHEMATICA
nn = 10^4; c[_] = False; a[0] = i = j = 0; Reap[Do[If[c[j], k = n - 2 - i, k = a[j]]; Set[{a[n], c[j], i, j}, {k, True, j, k}]; Sow[k], {n, nn}]][[-1, -1]] (* Michael De Vlieger, Feb 18 2023 *)
PROG
(C) See Links section.
CROSSREFS
KEYWORD
nonn
AUTHOR
David James Sycamore, Feb 16 2023
EXTENSIONS
More terms from Rémy Sigrist, Feb 18 2023
STATUS
approved