A134022 Number of negative trits in balanced ternary representation of n.
0, 0, 1, 0, 0, 2, 1, 1, 1, 0, 0, 1, 0, 0, 3, 2, 2, 2, 1, 1, 2, 1, 1, 2, 1, 1, 1, 0, 0, 1, 0, 0, 2, 1, 1, 1, 0, 0, 1, 0, 0, 4, 3, 3, 3, 2, 2, 3, 2, 2, 3, 2, 2, 2, 1, 1, 2, 1, 1, 3, 2, 2, 2, 1, 1, 2, 1, 1, 3, 2, 2, 2, 1, 1, 2, 1, 1, 2, 1, 1, 1, 0, 0, 1, 0, 0, 2, 1, 1, 1, 0, 0, 1, 0, 0, 3, 2, 2, 2, 1, 1, 2, 1, 1, 2
Offset: 0
Examples
100 = 1*3^4+1*3^3-1*3^2+0*3^1+1*3^0 == '++-0+': a(100) = 1; 200 = 1*3^5-1*3^4+1*3^3+1*3^2+1*3^1-1*3^0 == '+-+++-': a(200) = 2; 300 = 1*3^5+1*3^4-1*3^3+0*3^2+1*3^1+0*3^0 == '++-0+0': a(300) = 1.
References
- D. E. Knuth, The Art of Computer Programming, Addison-Wesley, Reading, MA, Vol 2, pp 173-175.
Links
- Reinhard Zumkeller, Table of n, a(n) for n = 0..10000
- Wikipedia, Balanced Ternary
Programs
-
Mathematica
Array[Count[#, -1] &[Prepend[IntegerDigits[#, 3], 0] //. {a___, b_, 2, c___} :> {a, b + 1, -1, c}] &, 105, 0] (* Michael De Vlieger, Jun 27 2020 *)
-
Python
def a(n): s=0 x=0 while n>0: x=n%3 n=n//3 if x==2: x=-1 n+=1 if x==-1: s+=1 return s print([a(n) for n in range(151)]) # Indranil Ghosh, Jun 07 2017