OFFSET
0,3
COMMENTS
This sequence is a self-inverse permutation of the nonnegative integers.
This sequence has infinitely many fixed points (A005836, among others).
LINKS
EXAMPLE
For n = 1562: the balanced ternary expansion of 1562 is "1T0110TT" (where T denotes -1), we have three blocks: "T0", "" and "0TT", their reversals are: "0T", "" and "TT0", so the balanced ternary expansion of a(1562) is "10T11TT0", and a(1562) = 2040.
PROG
(PARI) a(n) = { my (d = [], i = 1); while (n, d = concat(centerlift(Mod(n, 3)), d); n = (n - d[1])/3; ); for (j = 2, #d+1, if (j==#d+1 || d[i]==d[j], my (ii = i+1, jj = j-1); while (ii < jj, [d[ii], d[jj]] = [d[jj], d[ii]]; ii++; jj--; ); i = j; ); ); fromdigits(d, 3); }
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Rémy Sigrist, Apr 27 2024
STATUS
approved