login

Reminder: The OEIS is hiring a new managing editor, and the application deadline is January 26.

a(0)=0, a(1)=1, a(2)=2; a(3n) = a(n), a(3n+1) = a(n) + a(n+1), a(3n+2) = a(n+1) + a(n+2).
1

%I #16 Jul 17 2023 08:57:31

%S 0,1,2,1,3,3,2,3,4,1,4,6,3,6,5,3,5,5,2,5,7,3,7,5,4,5,5,1,5,10,4,10,9,

%T 6,9,9,3,9,11,6,11,8,5,8,8,3,8,10,5,10,7,5,7,7,2,7,12,5,12,10,7,10,10,

%U 3,10,12,7,12,9,5,9,9,4,9,10,5,10,6,5,6,6,1,6,15,5,15,14,10,14,14,4,14,19

%N a(0)=0, a(1)=1, a(2)=2; a(3n) = a(n), a(3n+1) = a(n) + a(n+1), a(3n+2) = a(n+1) + a(n+2).

%C Similar to A002487, but the base is 3.

%H G. C. Greubel, <a href="/A123143/b123143.txt">Table of n, a(n) for n = 0..5000</a>

%e a(11) = a(4) +a(5) = a(1) +a(2) +a(2) +a(3) = 2*(a(1) +a(2)) = 6.

%p 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

%t 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]];

%t Table[a[n], {n,0,100}] (* _Robert G. Wilson v_, Oct 07 2006 *)

%o (Magma)

%o function a(n) // a = A123143

%o if n le 2 then return n;

%o elif (n mod 3) eq 0 then return a(Floor(n/3));

%o elif (n mod 3) eq 1 then return a(Floor((n-1)/3)) + a(1 + Floor((n

%o -1)/3));

%o else return a(1 + Floor((n-2)/3)) + a(2 + Floor((n-2)/3));

%o end if;

%o end function;

%o [a(n): n in [0..100]]; // _G. C. Greubel_, Jul 16 2023

%o (SageMath)

%o def a(n): # a = A123143

%o if n<3: return n

%o elif (n%3)==0: return a(n//3)

%o elif (n%3)==1: return a((n-1)//3) + a((n+2)//3)

%o else: return a((n+1)//3) + a((n+4)//3)

%o [a(n) for n in range(101)] # _G. C. Greubel_, Jul 16 2023

%Y Cf. A002487.

%K nonn

%O 0,3

%A WAGNER Kurt (wagner.kurt(AT)chello.at), Oct 01 2006

%E More terms from _Robert G. Wilson v_ and _Emeric Deutsch_ Oct 07 2006