login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A081603 Number of 2's in ternary representation of n. 48

%I #50 Dec 10 2023 15:18:15

%S 0,0,1,0,0,1,1,1,2,0,0,1,0,0,1,1,1,2,1,1,2,1,1,2,2,2,3,0,0,1,0,0,1,1,

%T 1,2,0,0,1,0,0,1,1,1,2,1,1,2,1,1,2,2,2,3,1,1,2,1,1,2,2,2,3,1,1,2,1,1,

%U 2,2,2,3,2,2,3,2,2,3,3,3,4,0,0,1,0,0,1,1,1,2,0,0,1,0,0,1,1,1,2,1,1,2,1,1,2

%N Number of 2's in ternary representation of n.

%C Fixed point of the morphism: 0 ->001; 1 ->112; 2 ->223; 3 ->334, etc., starting from a(0)=0. - _Philippe Deléham_, Oct 26 2011

%H Reinhard Zumkeller, <a href="/A081603/b081603.txt">Table of n, a(n) for n = 0..10000</a>

%H F. T. Adams-Watters and F. Ruskey, <a href="https://cs.uwaterloo.ca/journals/JIS/VOL12/Ruskey2/ruskey14.html">Generating Functions for the Digital Sum and Other Digit Counting Sequences</a>, JIS 12 (2009) 09.5.6.

%H Eric Weisstein's World of Mathematics, <a href="http://mathworld.wolfram.com/Ternary.html">Ternary</a>.

%F a(n) = floor(n/2) if n < 3, otherwise a(floor(n/3)) + floor((n mod 3)/2).

%F A077267(n) + A062756(n) + a(n) = A081604(n);

%F a(n) = (A053735(n) - A062756(n))/2.

%p A081603 := proc(n)

%p local a,d ;

%p a := 0 ;

%p for d in convert(n,base,3) do

%p if d= 2 then

%p a := a+1 ;

%p end if;

%p end do:

%p a;

%p end proc: # _R. J. Mathar_, Jul 12 2016

%t Table[Count[IntegerDigits[n,3],2],{n,0,6!}] (* _Vladimir Joseph Stephan Orlovsky_, Jul 25 2009 *)

%t Nest[ Flatten[# /. a_Integer -> {a, a, a + 1}] &, {0}, 5] (* _Robert G. Wilson v_, May 20 2014 *)

%t DigitCount[Range[0,120],3,2] (* _Harvey P. Dale_, Jul 10 2019 *)

%o (Haskell)

%o a081603 0 = 0

%o a081603 n = a081603 n' + m `div` 2 where (n',m) = divMod n 3

%o -- _Reinhard Zumkeller_, Feb 21 2013

%o (PARI) a(n)=hammingweight(digits(n,3)\2); \\ _Ruud H.G. van Tol_, Dec 10 2023

%Y Cf. A007089, A074940, A005836, A081610, A081611, A117592 (2^a(n)).

%K nonn,base

%O 0,9

%A _Reinhard Zumkeller_, Mar 23 2003

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified August 26 18:31 EDT 2024. Contains 375462 sequences. (Running on oeis4.)