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 A134024 #24 Apr 28 2021 10:10:56 %S A134024 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,2,2,2,3,2,2, %T A134024 3,2,2,3,3,3,4,1,1,2,1,1,2,2,2,3,1,1,2,1,1,2,2,2,3,2,2,3,2,2,3,3,3,4, %U A134024 1,1,2,1,1,2,2,2,3,1,1,2,1,1,2,2,2,3,2,2,3,2,2,3,3,3,4,2,2,3,2,2,3,3,3,4,2 %N A134024 Number of positive trits in balanced ternary representation of n. %D A134024 D. E. Knuth, The Art of Computer Programming, Addison-Wesley, Reading, MA, Vol 2, pp 173-175. %H A134024 Reinhard Zumkeller, <a href="/A134024/b134024.txt">Table of n, a(n) for n = 0..10000</a> %H A134024 Wikipedia, <a href="http://en.wikipedia.org/wiki/Balanced_ternary">Balanced Ternary</a> %F A134024 a(n) = A134021(n) - A134022(n) - A134023(n); %F A134024 a(n) > 0 for n > 0. %F A134024 a(n) = A005812(n) - A134022(n) = A134022(n) + A065363(n). %e A134024 100=1*3^4+1*3^3-1*3^2+0*3^1+1*3^0=='++-0+': a(100)=3; %e A134024 200=1*3^5-1*3^4+1*3^3+1*3^2+1*3^1-1*3^0=='+-+++-': a(200)=4; %e A134024 300=1*3^5+1*3^4-1*3^3+0*3^2+1*3^1+0*3^0=='++-0+0': a(300)=3. %t A134024 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 A134024 (Python) %o A134024 def a(n): %o A134024 s=0 %o A134024 x=0 %o A134024 while n>0: %o A134024 x=n%3 %o A134024 n //= 3 %o A134024 if x==2: %o A134024 x=-1 %o A134024 n+=1 %o A134024 if x==1: s+=1 %o A134024 return s %o A134024 print([a(n) for n in range(151)]) # _Indranil Ghosh_, Jun 07 2017 %Y A134024 Cf. A005812, A059095, A065363, A134021, A134022, A134023. %K A134024 nonn,base %O A134024 0,5 %A A134024 _Reinhard Zumkeller_, Oct 19 2007