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.
%I A134022 #29 Apr 11 2021 04:51:33 %S A134022 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, %T A134022 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, %U A134022 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 %N A134022 Number of negative trits in balanced ternary representation of n. %D A134022 D. E. Knuth, The Art of Computer Programming, Addison-Wesley, Reading, MA, Vol 2, pp 173-175. %H A134022 Reinhard Zumkeller, <a href="/A134022/b134022.txt">Table of n, a(n) for n = 0..10000</a> %H A134022 Wikipedia, <a href="http://en.wikipedia.org/wiki/Balanced_ternary">Balanced Ternary</a> %F A134022 a(n) = A134021(n) - A134023(n) - A134024(n). %F A134022 a(n) = A005812(n) - A134024(n) = A134024(n) - A065363(n). %e A134022 100 = 1*3^4+1*3^3-1*3^2+0*3^1+1*3^0 == '++-0+': a(100) = 1; %e A134022 200 = 1*3^5-1*3^4+1*3^3+1*3^2+1*3^1-1*3^0 == '+-+++-': a(200) = 2; %e A134022 300 = 1*3^5+1*3^4-1*3^3+0*3^2+1*3^1+0*3^0 == '++-0+0': a(300) = 1. %t A134022 Array[Count[#, -1] &[Prepend[IntegerDigits[#, 3], 0] //. {a___, b_, 2, c___} :> {a, b + 1, -1, c}] &, 105, 0] (* _Michael De Vlieger_, Jun 27 2020 *) %o A134022 (Python) %o A134022 def a(n): %o A134022 s=0 %o A134022 x=0 %o A134022 while n>0: %o A134022 x=n%3 %o A134022 n=n//3 %o A134022 if x==2: %o A134022 x=-1 %o A134022 n+=1 %o A134022 if x==-1: s+=1 %o A134022 return s %o A134022 print([a(n) for n in range(151)]) # _Indranil Ghosh_, Jun 07 2017 %Y A134022 Cf. A059095, A134023, A134024. %K A134022 nonn,base %O A134022 0,6 %A A134022 _Reinhard Zumkeller_, Oct 19 2007