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

%I #18 Oct 07 2024 00:46:16

%S 0,1,2,2,4,3,4,3,8,3,6,4,8,3,6,4,16,7,6,4,12,7,8,5,16,7,6,4,12,7,8,5,

%T 32,15,14,8,12,7,8,5,24,11,14,8,16,7,10,6,32,15,14,8,12,7,8,5,24,11,

%U 14,8,16,7,10,6,64,31,30,16,28,15,16,9,24,11,14,8,16,7,10,6,48,23,22,12,28,15,16,9,32,15,14

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

%H Indranil Ghosh, <a href="/A283187/b283187.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="/A283187/a283187.pdf">Extended graphical example</a>

%e a(0) = 0;

%e a(1) = 1;

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

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

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

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

%t a[0] = 0; a[1] = 1; a[n_] := If[EvenQ[n], 2 a[n/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), 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==0 or n==1: return n

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

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

%o (Python)

%o from functools import lru_cache

%o @lru_cache(maxsize=None)

%o def A283187(n): return n if n <= 1 else A283187(n//2) + (-1 if A283187((n+1)//2) % 2 else 1) if n % 2 else 2*A283187(n//2) # _Chai Wah Wu_, Mar 08 2022

%Y Cf. A000079 (fixed points), A006165, A087808, A283165.

%K nonn,hear

%O 0,3

%A _Ilya Gutkovskiy_, Mar 02 2017