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.

A134022 Number of negative trits in balanced ternary representation of n.

Original entry on oeis.org

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

Views

Author

Reinhard Zumkeller, Oct 19 2007

Keywords

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.

Crossrefs

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

Formula

a(n) = A134021(n) - A134023(n) - A134024(n).
a(n) = A005812(n) - A134024(n) = A134024(n) - A065363(n).