OFFSET
0,3
COMMENTS
Similar to A002487, but the base is 3.
LINKS
G. C. Greubel, Table of n, a(n) for n = 0..5000
EXAMPLE
a(11) = a(4) +a(5) = a(1) +a(2) +a(2) +a(3) = 2*(a(1) +a(2)) = 6.
MAPLE
a[0]:=0: a[1]:=1: a[2]:=2: for n from 1 to 38 do a[3*n]:=a[n]: a[3*n+1]:=a[n]+a[n+1]: a[3*n+2]:=a[n+1]+a[n+2] od: seq(a[n], n=0..115); # Emeric Deutsch, Oct 07 2006
MATHEMATICA
a[0]=0; a[1]=1; a[2]=2; a[n_]:= Switch[Mod[n, 3], 0, a[n/3], 1, a[(n - 1)/3] + a[(n+2)/3], 2, a[(n+1)/3] + a[(n+4)/3]];
Table[a[n], {n, 0, 100}] (* Robert G. Wilson v, Oct 07 2006 *)
PROG
(Magma)
function a(n) // a = A123143
if n le 2 then return n;
elif (n mod 3) eq 0 then return a(Floor(n/3));
elif (n mod 3) eq 1 then return a(Floor((n-1)/3)) + a(1 + Floor((n
-1)/3));
else return a(1 + Floor((n-2)/3)) + a(2 + Floor((n-2)/3));
end if;
end function;
[a(n): n in [0..100]]; // G. C. Greubel, Jul 16 2023
(SageMath)
def a(n): # a = A123143
if n<3: return n
elif (n%3)==0: return a(n//3)
elif (n%3)==1: return a((n-1)//3) + a((n+2)//3)
else: return a((n+1)//3) + a((n+4)//3)
[a(n) for n in range(101)] # G. C. Greubel, Jul 16 2023
CROSSREFS
KEYWORD
nonn
AUTHOR
WAGNER Kurt (wagner.kurt(AT)chello.at), Oct 01 2006
EXTENSIONS
More terms from Robert G. Wilson v and Emeric Deutsch Oct 07 2006
STATUS
approved