login
a(0) = 0. Thereafter a(n+1) = a(a(n)) if a(n) has not occurred previously, otherwise a(n+1) = n - 1 - a(n-1).
1

%I #25 Feb 18 2023 20:49:47

%S 0,0,0,1,0,2,0,3,1,4,0,5,2,6,0,7,3,8,1,9,4,10,0,11,5,12,2,13,6,14,0,

%T 15,7,16,3,17,8,18,1,19,9,20,4,21,10,22,0,23,11,24,5,25,12,26,2,27,13,

%U 28,6,29,14,30,0,31,15,32,7,33,16,34,3,35,17,36,8

%N a(0) = 0. Thereafter a(n+1) = a(a(n)) if a(n) has not occurred previously, otherwise a(n+1) = n - 1 - a(n-1).

%C 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.

%C Apart from a(1) = 0 every repeat term is followed by a novel term, and vice versa.

%C Every nonnegative integer appears infinitely many times.

%C The proper subsequence given by a(2*k) for k >= 2 is the sequence itself, which is therefore fractal.

%C Starting from a(1) = 0 the sequence is the nonnegative integers interleaved with itself.

%H Winston de Greef, <a href="/A360692/b360692.txt">Table of n, a(n) for n = 0..10000</a>

%H Rémy Sigrist, <a href="/A360692/a360692.txt">C program</a>

%F a(2*n + 1) = n for all n >= 0.

%F A027383(n) = 0. (n >= 0) gives the positions of all zeros after a(0) = 0.

%F a((2*k + 3)*2^n - 2)) = k (n >= 0) gives the positions of all k > 0.

%F The number of nonnegative terms occurring between consecutive zeros is 0,0,1,1,3,3,7,7,15,15,... (A000225(n), repeat).

%F a(n) = A101279(n+2) - 1. - _Rémy Sigrist_, Feb 18 2023

%e 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.

%e 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.

%e a(16) = 3, a repeat term (last seen at a(7)), so a(17) = 15 - a(15) = 15 - 7 = 8.

%t 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 *)

%o (C) See Links section.

%Y Cf. A000225, A027383, A051633, A101279, A176488, A176449.

%K nonn

%O 0,6

%A _David James Sycamore_, Feb 16 2023

%E More terms from _Rémy Sigrist_, Feb 18 2023