OFFSET
1,2
LINKS
Lei Zhou, Table of n, a(n) for n = 1..10000
EXAMPLE
In balanced ternary notation, 8=(10T)_bt, where we use T to represent -1. Reverse digits of (10T)_bt is (T01)_bt = -8. So 8 is in this sequence.
Similarly, 2240 = (1001T00T)_bt, whose reverse digits is (T00T1001)_bt = -2240. So 2240 is in this sequence.
MATHEMATICA
BTDigits[m_Integer, g_] :=
Module[{n = m, d, sign, t = g},
If[n != 0, If[n > 0, sign = 1, sign = -1; n = -n];
d = Ceiling[Log[3, n]]; If[3^d - n <= ((3^d - 1)/2), d++];
While[Length[t] < d, PrependTo[t, 0]]; t[[Length[t] + 1 - d]] = sign;
t = BTDigits[sign*(n - 3^(d - 1)), t]]; t];
ct = 1; n = 0; m = 0; dg = 0; switch = 1; res = {0}; While[ct < 50, n++;
bits = BTDigits[n, {0}]; If[lb = Length[bits]; lb > dg,
If[switch == 0, n = m; switch = 1; OK = 0, dg = lb; m = n - 1;
switch = 0; OK = 1], OK = 1]; If[OK == 1, rbt = -Reverse[bits];
If[switch == 1, nb = Join[bits, {0}], nb = bits];
nb = Join[nb, rbt]; nb = Reverse[nb]; data = 0;
Do[data = data + 3^(i - 1)*nb[[i]], {i, 1, Length[nb]}]; ct++;
AppendTo[res, data]]]; res
CROSSREFS
KEYWORD
nonn,easy,base
AUTHOR
Lei Zhou, Dec 13 2013
STATUS
approved