login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

Nonnegative integers in balanced ternary representation (with 2 standing for -1 digit).
20

%I #14 Jun 06 2017 19:45:42

%S 0,1,12,10,11,122,120,121,102,100,101,112,110,111,1222,1220,1221,1202,

%T 1200,1201,1212,1210,1211,1022,1020,1021,1002,1000,1001,1012,1010,

%U 1011,1122,1120,1121,1102,1100,1101,1112,1110,1111,12222,12220,12221

%N Nonnegative integers in balanced ternary representation (with 2 standing for -1 digit).

%C Sequence A117967 in ternary. (See there for more references.)

%C From _Daniel Forgues_, Mar 22 2010: (Start)

%C The balanced ternary digits {-1, 0, +1} (balanced trits) of a(n) are being represented by {2, 0, 1} respectively in this sequence.

%C The sign of a(n) is given by the sign of its leading trit.

%C The number k, k >= 0, of trailing "0"s of a(n) indicates that a(n) is divisible by 3^k.

%C a(n) is even/odd if it has an even/odd count of nonzero trits. (End)

%H Daniel Forgues, <a href="/A140267/b140267.txt">Table of n, a(n) for n = 0..100000</a>

%H Jeff Connelly, <a href="http://xyzzy.freeshell.org/trinary/CPE%20Report%20-%20Ternary%20Computing%20Testbed%20-%20RC6a.pdf">Ternary Computing Testbed 3-Trit Computer Architecture</a>, 2008. - _Daniel Forgues_, Mar 23 2010

%H Brian Hayes, <a href="http://www.americanscientist.org/issues/pub/third-base/1">Third Base</a>, American Scientist, November-December 2001. - _Daniel Forgues_, Mar 23 2010

%H Ternary.info Forum, <a href="http://ternary.info/modules/newbb/viewtopic.php?topic_id=116&amp;forum=10">Balanced ternary arithmetics</a>. - _Daniel Forgues_, Mar 23 2010

%e For example a(2) = 12, as 1*3 + -1*1 = 2. Similarly, a(19) = 1201, as 1*27 + -1*9 + 0*3 + 1*1 = 19.

%o (Python)

%o from sympy.ntheory.factor_ import digits

%o def a004488(n): return int("".join([str((3 - i)%3) for i in digits(n, 3)[1:]]), 3)

%o def a117968(n):

%o if n==1: return 2

%o if n%3==0: return 3*a117968(n/3)

%o elif n%3==1: return 3*a117968((n - 1)/3) + 2

%o else: return 3*a117968((n + 1)/3) + 1

%o def a117967(n): return 0 if n==0 else a004488(a117968(n))

%o def a(n): return int("".join(map(str, digits(a117967(n), 3)[1:]))) # _Indranil Ghosh_, Jun 06 2017

%Y a(n) = A007089(A117967(n)). Cf. A140268.

%K nonn,base

%O 0,3

%A _Antti Karttunen_, May 19 2008, prompted by _Eric Angelini_'s posting on SeqFan mailing list on Sep 15 2005.

%E Definition edited by _Daniel Forgues_, Mar 24 2010