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.

A134021 Length of n in balanced ternary representation.

Original entry on oeis.org

1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5
Offset: 0

Views

Author

Reinhard Zumkeller, Oct 19 2007

Keywords

Comments

Shifted variant of A064099.

Examples

			100 = 1*3^4+1*3^3-1*3^2+0*3^1+1*3^0: a(100) = |++-0+| = 5.
200 = 1*3^5-1*3^4+1*3^3+1*3^2+1*3^1-1*3^0: a(200) = |+-+++-| = 6.
300 = 1*3^5+1*3^4-1*3^3+0*3^2+1*3^1+0*3^0: a(300) = |++-0+0| = 6.
		

References

  • Donald E. Knuth, The Art of Computer Programming, Addison-Wesley, Reading, MA, Vol. 2, pp. 173-175.

Crossrefs

Programs

  • Mathematica
    a[n_] := Ceiling[Log[3, 2*n+1]]; a[0] = 1; Array[a, 100, 0] (* Amiram Eldar, Apr 03 2025 *)
  • Python
    def a(n):
        if n==0: return 1
        s=0
        x=0
        while n>0:
            x=n%3
            n=n//3
            if x==2:
                x=-1
                n+=1
            s+=1
        return s
    print([a(n) for n in range(101)]) # Indranil Ghosh, Jun 07 2017

Formula

For n > 0: a(n) = ceiling(log(2*n+1)/log(3)).
a(n) = A134022(n) + A134023(n) + A134024(n).
0 <= a(n) - A081604(n) <= 1.
a(A134025(n)) = A081604(A134025(n)); a(A134026(n)) = A081604(A134026(n))+1.
a(A134027(n)) = a(n); a(abs(A134028(n))) <= a(n).
a(n) = A064099(n-1) for n>1.
n = Sum_{k=0..a(n)-1} (A059095(A134421(n)-2-k)*3^k), for n > 0. - Reinhard Zumkeller, Oct 25 2007
a(n) = A005812(n) + A134023(n).