OFFSET
0,3
LINKS
Indranil Ghosh, Table of n, a(n) for n = 0..10000
Michael Gilleland, Some Self-Similar Integer Sequences
Ilya Gutkovskiy, Extended graphical example
EXAMPLE
a(0) = 0;
a(1) = 1;
a(2) = a(2*1) = 2*a(1) = 2*1 = 2;
a(3) = a(2*1+1) = a(1) + (-1)^a(2) = 1 + (-1)^2 = 2;
a(4) = a(2*2) = 2*a(2) = 2*2 = 4;
a(5) = a(2*2+1) = a(2) + (-1)^a(3) = 2 + (-1)^2 = 3, etc.
MATHEMATICA
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}]
PROG
(PARI)
a(n) = if (n<2, n, if (n%2==0, 2*a(n/2), a((n-1)/2)+(-1)^(a(n+1)/2)));
tabl(nn)={for (n=0, nn, print1(a(n), ", "); ); };
tabl(90); \\ Indranil Ghosh, Mar 03 2017
(Python)
def a(n):
if n==0 or n==1: return n
if n%2==0: return int(2*a(n/2))
else: return int(a((n-1)/2)+(-1)**a((n+1)/2)) # Indranil Ghosh, Mar 03 2017
(Python)
from functools import lru_cache
@lru_cache(maxsize=None)
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
CROSSREFS
KEYWORD
nonn,hear
AUTHOR
Ilya Gutkovskiy, Mar 02 2017
STATUS
approved