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.

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

This page as a plain text file.
%I A327252 #41 Sep 20 2019 10:49:41
%S A327252 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,
%T A327252 -13,1,28,-26,10,37,-17,-8,19,-35,4,31,-23,13,40,-14,-5,22,-32,-2,25,
%U A327252 -29,7,34,-20,-11,16,-38,-1,26,-28,8,35,-19,-10,17,-37,2,29,-25,11
%N A327252 Balanced reversed ternary: Write n as ternary, reverse the order of the digits, then replace all 2's with (-1)'s.
%H A327252 Rémy Sigrist, <a href="/A327252/b327252.txt">Table of n, a(n) for n = 0..19683</a>
%e A327252 5 in base 3 is 12; reversing the ternary gives 21; replacing the 2 with (-1) gives (-1),1 which is -2 in decimal.
%p A327252 a:= proc(n) local m, r; m, r:= n, 0;
%p A327252       while m>0 do m, r:= iquo(m, 3), 3*r+mods(m, 3) od; r
%p A327252     end:
%p A327252 seq(a(n), n=0..3^4-1);  # _Alois P. Heinz_, Sep 17 2019
%t A327252 a[n_] := FromDigits[Reverse[IntegerDigits[n, 3]] /. {2 -> -1}, 3]; Array[a, 67, 0] (* _Giovanni Resta_, Sep 17 2019 *)
%o A327252 (Python)
%o A327252 def a(n):
%o A327252     ternary = []
%o A327252     i = math.floor(math.log(n,3))
%o A327252     while i >= 0:
%o A327252         for j in range (2, -1, -1):
%o A327252             if j*(3**i) <= n:
%o A327252                 if (j==2): ternary.append(-1)
%o A327252                 else: ternary.append(j)
%o A327252                 n -= j*(3**i)
%o A327252                 break
%o A327252         i -=1
%o A327252     for k in range (0, len(ternary)):
%o A327252         n += ternary[k]*(3**k)
%o A327252     return n
%o A327252 (PARI) a(n) = fromdigits(apply(d -> if (d==2, -1, d), Vecrev(digits(n,3))), 3) \\ _Rémy Sigrist_, Sep 15 2019
%Y A327252 Cf. A134028 (reversed balanced ternary, i.e. balancing the ternary, then reversing the ternary and transforming back into decimal), A117966 (balanced ternary enumeration).
%K A327252 sign,look,base
%O A327252 0,5
%A A327252 _Elisabeth Zemack_, Sep 15 2019