OFFSET
0,3
COMMENTS
This sequence is a self-inverse permutation of the nonnegative integers.
This sequence has infinitely many fixed points (A125292, among others).
LINKS
EXAMPLE
For n = 5323: the ternary expansion of 5323 is "21022011", the corresponding leading digit is "2", we have three blocks: "10", "" and "011", their reversals are: "01", "" and "110", so the ternary expansion of a(5323) is "20122110", and a(5323) = 4845.
PROG
(PARI) a(n, base = 3) = { my (d = digits(n, base), i = 1); 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, base); }
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Rémy Sigrist, Apr 27 2024
STATUS
approved