cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A081603 Number of 2's in ternary representation of n.

This page as a plain text file.
%I A081603 #54 Feb 16 2025 08:32:48
%S A081603 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 A081603 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 A081603 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 A081603 Number of 2's in ternary representation of n.
%C A081603 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 A081603 Reinhard Zumkeller, <a href="/A081603/b081603.txt">Table of n, a(n) for n = 0..10000</a>
%H A081603 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 A081603 Eric Weisstein's World of Mathematics, <a href="https://mathworld.wolfram.com/Ternary.html">Ternary</a>.
%F A081603 a(n) = floor(n/2) if n < 3, otherwise a(floor(n/3)) + floor((n mod 3)/2).
%F A081603 A077267(n) + A062756(n) + a(n) = A081604(n);
%F A081603 a(n) = (A053735(n) - A062756(n))/2.
%p A081603 A081603 := proc(n)
%p A081603     local a,d ;
%p A081603     a := 0 ;
%p A081603     for d in convert(n,base,3) do
%p A081603         if d= 2 then
%p A081603             a := a+1 ;
%p A081603         end if;
%p A081603     end do:
%p A081603     a;
%p A081603 end proc: # _R. J. Mathar_, Jul 12 2016
%t A081603 Table[Count[IntegerDigits[n,3],2],{n,0,6!}] (* _Vladimir Joseph Stephan Orlovsky_, Jul 25 2009 *)
%t A081603 Nest[ Flatten[# /. a_Integer -> {a, a, a + 1}] &, {0}, 5] (* _Robert G. Wilson v_, May 20 2014 *)
%t A081603 DigitCount[Range[0,120],3,2] (* _Harvey P. Dale_, Jul 10 2019 *)
%o A081603 (Haskell)
%o A081603 a081603 0 = 0
%o A081603 a081603 n = a081603 n' + m `div` 2 where (n',m) = divMod n 3
%o A081603 -- _Reinhard Zumkeller_, Feb 21 2013
%o A081603 (PARI) a(n)=hammingweight(digits(n,3)\2); \\ _Ruud H.G. van Tol_, Dec 10 2023
%o A081603 (Python)
%o A081603 from gmpy2 import digits
%o A081603 def A081603(n): return digits(n,3).count('2') # _Chai Wah Wu_, Dec 05 2024
%Y A081603 Cf. A007089, A074940, A005836, A081610, A081611, A117592 (2^a(n)).
%K A081603 nonn,base
%O A081603 0,9
%A A081603 _Reinhard Zumkeller_, Mar 23 2003