cp's OEIS Frontend

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.

A134023 Number of zeros in balanced ternary representation of n.

This page as a plain text file.
%I A134023 #25 Mar 29 2021 15:07:09
%S A134023 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 A134023 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 A134023 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 A134023 Number of zeros in balanced ternary representation of n.
%D A134023 D. E. Knuth, The Art of Computer Programming, Addison-Wesley, Reading, MA, Vol 2, pp 173-175.
%H A134023 Reinhard Zumkeller, <a href="/A134023/b134023.txt">Table of n, a(n) for n = 0..10000</a>
%H A134023 Wikipedia, <a href="http://en.wikipedia.org/wiki/Balanced_ternary">Balanced Ternary</a>
%F A134023 a(n) = A134021(n) - A134022(n) - A134024(n).
%F A134023 a(n) = A134021(n) - A005812(n).
%e A134023 100=1*3^4+1*3^3-1*3^2+0*3^1+1*3^0=='++-0+': a(100)=1;
%e A134023 200=1*3^5-1*3^4+1*3^3+1*3^2+1*3^1-1*3^0=='+-+++-': a(200)=0;
%e A134023 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 A134023 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 A134023 (Python)
%o A134023 def a(n):
%o A134023     if n==0: return 1
%o A134023     s=0
%o A134023     x=0
%o A134023     while n>0:
%o A134023         x=n%3
%o A134023         n=n//3
%o A134023         if x==2:
%o A134023             x=-1
%o A134023             n+=1
%o A134023         if x==0: s+=1
%o A134023     return s
%o A134023 print([a(n) for n in range(101)]) # _Indranil Ghosh_, Jun 07 2017
%Y A134023 Cf. A005812, A059095, A134021, A134022, A134024.
%K A134023 nonn,base
%O A134023 0,10
%A A134023 _Reinhard Zumkeller_, Oct 19 2007