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.

User: Elisabeth Zemack

Elisabeth Zemack's wiki page.

Elisabeth Zemack has authored 1 sequences.

A327252 Balanced reversed ternary: Write n as ternary, reverse the order of the digits, then replace all 2's with (-1)'s.

Original entry on oeis.org

0, 1, -1, 1, 4, -2, -1, 2, -4, 1, 10, -8, 4, 13, -5, -2, 7, -11, -1, 8, -10, 2, 11, -7, -4, 5, -13, 1, 28, -26, 10, 37, -17, -8, 19, -35, 4, 31, -23, 13, 40, -14, -5, 22, -32, -2, 25, -29, 7, 34, -20, -11, 16, -38, -1, 26, -28, 8, 35, -19, -10, 17, -37, 2, 29, -25, 11
Offset: 0

Author

Elisabeth Zemack, Sep 15 2019

Keywords

Examples

			5 in base 3 is 12; reversing the ternary gives 21; replacing the 2 with (-1) gives (-1),1 which is -2 in decimal.
		

Crossrefs

Cf. A134028 (reversed balanced ternary, i.e. balancing the ternary, then reversing the ternary and transforming back into decimal), A117966 (balanced ternary enumeration).

Programs

  • Maple
    a:= proc(n) local m, r; m, r:= n, 0;
          while m>0 do m, r:= iquo(m, 3), 3*r+mods(m, 3) od; r
        end:
    seq(a(n), n=0..3^4-1);  # Alois P. Heinz, Sep 17 2019
  • Mathematica
    a[n_] := FromDigits[Reverse[IntegerDigits[n, 3]] /. {2 -> -1}, 3]; Array[a, 67, 0] (* Giovanni Resta, Sep 17 2019 *)
  • PARI
    a(n) = fromdigits(apply(d -> if (d==2, -1, d), Vecrev(digits(n,3))), 3) \\ Rémy Sigrist, Sep 15 2019
  • Python
    def a(n):
        ternary = []
        i = math.floor(math.log(n,3))
        while i >= 0:
            for j in range (2, -1, -1):
                if j*(3**i) <= n:
                    if (j==2): ternary.append(-1)
                    else: ternary.append(j)
                    n -= j*(3**i)
                    break
            i -=1
        for k in range (0, len(ternary)):
            n += ternary[k]*(3**k)
        return n