The OEIS mourns the passing of Jim Simons and is grateful to the Simons Foundation for its support of research in many branches of science, including the OEIS.
login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A327252 Balanced reversed ternary: Write n as ternary, reverse the order of the digits, then replace all 2's with (-1)'s. 1
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 (list; graph; refs; listen; history; text; internal format)
OFFSET
0,5
LINKS
EXAMPLE
5 in base 3 is 12; reversing the ternary gives 21; replacing the 2 with (-1) gives (-1),1 which is -2 in decimal.
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 *)
PROG
(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
(PARI) a(n) = fromdigits(apply(d -> if (d==2, -1, d), Vecrev(digits(n, 3))), 3) \\ Rémy Sigrist, Sep 15 2019
CROSSREFS
Cf. A134028 (reversed balanced ternary, i.e. balancing the ternary, then reversing the ternary and transforming back into decimal), A117966 (balanced ternary enumeration).
Sequence in context: A016507 A270047 A132116 * A229974 A364789 A281065
KEYWORD
sign,look,base
AUTHOR
Elisabeth Zemack, Sep 15 2019
STATUS
approved

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified May 15 13:23 EDT 2024. Contains 372540 sequences. (Running on oeis4.)