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!)
A134023 Number of zeros in balanced ternary representation of n. 8

%I #25 Mar 29 2021 15:07:09

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

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

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

%N Number of zeros in balanced ternary representation of n.

%D D. E. Knuth, The Art of Computer Programming, Addison-Wesley, Reading, MA, Vol 2, pp 173-175.

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

%H Wikipedia, <a href="http://en.wikipedia.org/wiki/Balanced_ternary">Balanced Ternary</a>

%F a(n) = A134021(n) - A134022(n) - A134024(n).

%F a(n) = A134021(n) - A005812(n).

%e 100=1*3^4+1*3^3-1*3^2+0*3^1+1*3^0=='++-0+': a(100)=1;

%e 200=1*3^5-1*3^4+1*3^3+1*3^2+1*3^1-1*3^0=='+-+++-': a(200)=0;

%e 300=1*3^5+1*3^4-1*3^3+0*3^2+1*3^1+0*3^0=='++-0+0': a(300)=2.

%t Array[Count[If[First@ # == 0, Rest@ #, #], 0] &[Prepend[IntegerDigits[#, 3], 0] //. {a___, b_, 2, c___} :> {a, b + 1, -1, c}] &, 105, 0] (* _Michael De Vlieger_, Jun 27 2020 *)

%o (Python)

%o def a(n):

%o if n==0: return 1

%o s=0

%o x=0

%o while n>0:

%o x=n%3

%o n=n//3

%o if x==2:

%o x=-1

%o n+=1

%o if x==0: s+=1

%o return s

%o print([a(n) for n in range(101)]) # _Indranil Ghosh_, Jun 07 2017

%Y Cf. A005812, A059095, A134021, A134022, A134024.

%K nonn,base

%O 0,10

%A _Reinhard Zumkeller_, Oct 19 2007

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 March 28 09:04 EDT 2024. Contains 371240 sequences. (Running on oeis4.)