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.

Showing 1-4 of 4 results.

A065363 Sum of balanced ternary digits in n. Replace 3^k with 1 in balanced ternary expansion of n.

Original entry on oeis.org

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

Views

Author

Marc LeBrun, Oct 31 2001

Keywords

Comments

Notation: (3)(1).
Extension to negative n: a(-n) = -a(n). - Franklin T. Adams-Watters, May 13 2009
Row sums of A059095. - Rémy Sigrist, Oct 05 2019

Examples

			5 = + 1(9) - 1(3) - 1(1) -> +1 - 1 - 1 = -1 = a(5).
		

Crossrefs

Cf. A059095, A065364, A053735. See A134452 for iterations.

Programs

  • Maple
    a:= proc(n) `if`(n=0, 0, (d-> `if`(d=2,
          a(q+1)-1, d+a(q)))(irem(n, 3, 'q')))
        end:
    seq(a(n), n=0..120);  # Alois P. Heinz, Jan 09 2020
  • Mathematica
    balTernDigits[0] := {0}; balTernDigits[n_/;n > 0] := Module[{unParsed = n, currRem, currExp = 1, digitList = {}, nextDigit}, While[unParsed > 0, If[unParsed == 3^(currExp - 1), digitList = Append[digitList, 1]; unParsed = 0, currRem = Mod[unParsed, 3^currExp]/3^(currExp - 1); nextDigit = Switch[currRem, 0, 0, 2, -1, 1, 1]; digitList = Append[digitList, nextDigit]; unParsed = unParsed - nextDigit * 3^(currExp - 1)]; currExp++]; digitList = Reverse[digitList]; Return[digitList]]; balTernDigits[n_/;n < 0] := (-1)balTernDigits[Abs[n]]; Table[Plus@@balTernDigits[n], {n, 0, 108}] (* Alonso del Arte, Feb 25 2011 *)
    terVal[lst_List] := Reverse[lst].(3^Range[0, Length[lst] - 1]); maxDig = 4; t = Table[0, {3 * 3^maxDig/2}]; t[[1]] = 1; Do[d = IntegerDigits[Range[0, 3^dig - 1], 3, dig]/.{2 -> -1}; d = Prepend[#, 1]&/@d; t[[terVal/@d]] = Total/@d, {dig, maxDig}]; Prepend[t, 0] (* T. D. Noe, Feb 24 2011 *)
    Array[Total[Prepend[IntegerDigits[#, 3], 0] //. {a___, b_, 2, c___} :> {a, b + 1, -1, c}] &, 109, 0] (* Michael De Vlieger, Jun 27 2020 *)
  • PARI
    bt(n)=my(d=digits(n,3),c=1); while(c, if(d[1]==2, d=concat(0,d)); c=0; for(i=2,#d, if(d[i]==2,d[i]=-1;d[i-1]+=1;c=1))); d
    a(n)=vecsum(bt(n)) \\ Charles R Greathouse IV, May 07 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
            s+=x
        return s
    print([a(n) for n in range(101)]) # Indranil Ghosh, Jun 06 2017
    

Formula

G.f.: (1/(1-x))*Sum_{k>=0} (x^3^k - x^(2*3^k))/(x^((3^k-1)/2)*(1 + x^3^k + x^(2*3^k))). - Franklin T. Adams-Watters, May 13 2009
a(n) = A134024(n) - A134022(n). - Reinhard Zumkeller, Dec 16 2010
a(3*n - 1) = a(n) - 1, a(3*n) = a(n), a(3*n + 1) = a(n) + 1. - Thomas König, Jun 24 2020
a(n) = A053735(2n) - A053735(n). This can be shown with constructing balanced ternary representation of n: Add n and n with carry, and then subtract n from the sum without borrow. - Yifan Xie, Dec 24 2024

A065368 Alternating sum of ternary digits in n. Replace 3^k with (-1)^k in ternary expansion of n.

Original entry on oeis.org

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

Views

Author

Marc LeBrun, Oct 31 2001

Keywords

Comments

Notation: (3)[n](-1).
Fixed point of the morphism 0 -> 0,1,2; 1 -> -1,0,1; 2 -> -2,-1,0; ...; n -> -n,-n+1,-n+2. - Philippe Deléham, Oct 22 2011

Examples

			15 = +1(9)+2(3)+0(1) -> +1(+1)+2(-1)+0(+1) = -1 = a(15).
		

Crossrefs

Programs

  • Python
    from sympy.ntheory.digits import digits
    def a(n):
        return sum(bi*(-1)**k for k, bi in enumerate(digits(n, 3)[1:][::-1]))
    print([a(n) for n in range(104)]) # Michael S. Branicky, Jul 28 2021
    
  • Python
    from sympy.ntheory import digits
    def A065368(n): return sum((0, 1, 2, -1, 0, 1, -2, -1, 0)[i] for i in digits(n,9)[1:]) # Chai Wah Wu, Jul 19 2024

Formula

a(n) = Sum_{k>=0} A030341(n,k)*(-1)^k. - Philippe Deléham, Oct 22 2011.
G.f. A(x) satisfies: A(x) = x * (1 + 2*x) / (1 - x^3) - (1 + x + x^2) * A(x^3). - Ilya Gutkovskiy, Jul 28 2021

Extensions

Initial 0 added by Philippe Deléham, Oct 22 2011

A065366 Replace 3^k with (-2)^k in balanced ternary expansion of n.

Original entry on oeis.org

1, -3, -2, -1, 5, 6, 7, 3, 4, 5, 1, 2, 3, -11, -10, -9, -13, -12, -11, -15, -14, -13, -7, -6, -5, -9, -8, -7, -11, -10, -9, -3, -2, -1, -5, -4, -3, -7, -6, -5, 21, 22, 23, 19, 20, 21, 17, 18, 19, 25, 26, 27, 23, 24, 25, 21, 22, 23, 29, 30, 31, 27, 28, 29, 25, 26, 27, 13, 14, 15, 11, 12, 13, 9, 10, 11, 17, 18, 19, 15
Offset: 1

Views

Author

Marc LeBrun, Oct 31 2001

Keywords

Comments

Notation: (3)< n >(2)

Examples

			5 = +1(9)-1(3)-1(1) -> +1(4)-1(-2)-1(1) = 5 = a(5)
		

Crossrefs

A065367 Replace 3^k with (-3)^k in balanced ternary expansion of n.

Original entry on oeis.org

1, -4, -3, -2, 11, 12, 13, 8, 9, 10, 5, 6, 7, -34, -33, -32, -37, -36, -35, -40, -39, -38, -25, -24, -23, -28, -27, -26, -31, -30, -29, -16, -15, -14, -19, -18, -17, -22, -21, -20, 101, 102, 103, 98, 99, 100, 95, 96, 97, 110, 111, 112, 107, 108, 109, 104, 105, 106, 119, 120, 121, 116, 117, 118, 113
Offset: 1

Views

Author

Marc LeBrun, Oct 31 2001

Keywords

Comments

Notation: (3)< n >(-3)

Examples

			5 = +1(9)-1(3)-1(1) -> +1(9)-1(-3)-1(1) = 11 = a(5)
		

Crossrefs

Showing 1-4 of 4 results.