login
a(0) = 0; a(1) = 1; a(2*n) = 2*a(n), a(2*n+1) = 2*a(n) + (-1)^a(n+1).
3

%I #19 Nov 21 2024 15:30:00

%S 0,1,2,3,4,3,6,7,8,7,6,7,12,11,14,15,16,15,14,15,12,11,14,15,24,23,22,

%T 23,28,27,30,31,32,31,30,31,28,27,30,31,24,23,22,23,28,27,30,31,48,47,

%U 46,47,44,43,46,47,56,55,54,55,60,59,62,63,64,63,62,63,60,59,62,63,56,55,54,55,60,59,62,63,48,47,46,47,44,43,46,47,56,55,54

%N a(0) = 0; a(1) = 1; a(2*n) = 2*a(n), a(2*n+1) = 2*a(n) + (-1)^a(n+1).

%H Indranil Ghosh, <a href="/A283165/b283165.txt">Table of n, a(n) for n = 0..10000</a>

%H Michael Gilleland, <a href="/selfsimilar.html">Some Self-Similar Integer Sequences</a>

%H Ilya Gutkovskiy, <a href="/A283165/a283165.pdf">Extended graphical example </a>

%e a(0) = 0;

%e a(1) = 1;

%e a(2) = a(2*1) = 2*a(1) = 2;

%e a(3) = a(2*1+1) = 2*a(1) + (-1)^a(2) = 2*1 + (-1)^2 = 3;

%e a(4) = a(2*2) = 2*a(2) = 2*2 = 4;

%e a(5) = a(2*2+1) = 2*a(2) + (-1)^a(3) = 2*2 + (-1)^3 = 3, etc.

%t a[0] = 0; a[1] = 1; a[n_] := If[EvenQ[n], 2 a[n/2], 2 a[(n - 1)/2] + (-1)^a[(n + 1)/2]]; Table[a[n], {n, 0, 90}]

%o (PARI)

%o a(n) = if (n<2, n, if (n%2==0, 2*a(n/2), 2*a((n-1)/2)+(-1)^(a(n+1)/2)));

%o tabl(nn)={for (n=0, nn, print1(a(n), ", "); ); };

%o tabl(90); \\ _Indranil Ghosh_, Mar 03 2017

%o (Python)

%o def a(n):

%o if n<2: return n

%o if n%2==0: return 2*a(n//2)

%o else: return 2*a((n-1)//2)+(-1)**a((n+1)//2) # _Indranil Ghosh_, Mar 03 2017

%Y Cf. A023758 (fixed points), A052499 (records), A080100, A087808.

%K nonn,changed

%O 0,3

%A _Ilya Gutkovskiy_, Mar 02 2017