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 A005812 M0111 #41 Apr 30 2021 06:07:00 %S A005812 0,1,2,1,2,3,2,3,2,1,2,3,2,3,4,3,4,3,2,3,4,3,4,3,2,3,2,1,2,3,2,3,4,3, %T A005812 4,3,2,3,4,3,4,5,4,5,4,3,4,5,4,5,4,3,4,3,2,3,4,3,4,5,4,5,4,3,4,5,4,5, %U A005812 4,3,4,3,2,3,4,3,4,3,2,3,2,1,2,3,2,3,4,3,4,3,2,3,4,3,4,5,4,5,4,3,4,5,4,5,4,3 %N A005812 Weight of balanced ternary representation of n. %C A005812 Weight of n means count of nonzero digits of n. - _Daniel Forgues_, Mar 24 2010 %C A005812 a(n) = A134022(n) + A134024(n) = A134021(n) - A134023(n). %D A005812 N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence). %H A005812 Daniel Forgues, <a href="/A005812/b005812.txt">Table of n, a(n) for n = 0..100000</a> %H A005812 P. Flajolet and Lyle Ramshaw, <a href="http://dx.doi.org/10.1137/0209014">A note on Gray code and odd-even merge</a>, SIAM J. Comput. 9 (1980), 142-158. %H A005812 Michael Gilleland, <a href="/selfsimilar.html">Some Self-Similar Integer Sequences</a> %F A005812 a(3n)=a(n), a(3n+1)=a(n)+1, a(9n+2)=a(n)+2, a(9n+5)=a(3n+2)+1, a(9n+8)=a(3n+2). %F A005812 a(n) = Sum_{k>0} floor(|2*sin(n*Pi/3^k)|). - _Toshitaka Suzuki_, Sep 10 2006 %t A005812 a[n_] := With[{q=Round[n/3]}, Abs[n-3q]+a[q]]; a[0]=0; Table[a[n], {n, 0, 105}](* _Jean-François Alcover_, Nov 25 2011, after Pari *) %o A005812 (Lisp) (defun btw (n) (if (= n 0) 0 (multiple-value-bind (q r) (round n 3) (+ (abs r) (btw q))))) %o A005812 (PARI) a(n)=local(q); if(n<=0,0,q=round(n/3); abs(n-3*q)+a(q)) %o A005812 (Python) %o A005812 def a(n): %o A005812 s=0 %o A005812 x=0 %o A005812 while n>0: %o A005812 x=n%3 %o A005812 n//=3 %o A005812 if x==2: %o A005812 x=-1 %o A005812 n+=1 %o A005812 if x!=0: s+=1 %o A005812 return s %o A005812 print([a(n) for n in range(101)]) # _Indranil Ghosh_, Jun 07 2017 %K A005812 easy,nonn,nice %O A005812 0,3 %A A005812 _N. J. A. Sloane_, _Jeffrey Shallit_ %E A005812 Additional terms from _Allan C. Wechsler_