login
A372317
For any n > 0 with leading ternary digit h = A122586(n), reverse digits in blocks in ternary expansion of n where blocks are separated by h's; a(0) = 0.
2
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 12, 13, 14, 11, 16, 17, 18, 21, 20, 19, 22, 23, 24, 25, 26, 27, 28, 45, 30, 31, 32, 33, 46, 51, 36, 37, 42, 39, 40, 41, 38, 43, 44, 29, 34, 47, 48, 49, 50, 35, 52, 53, 54, 63, 56, 57, 66, 65, 60, 61, 62, 55, 64, 59, 58, 67
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).
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
See A367307 and A372318 for similar sequences.
Sequence in context: A271838 A194846 A194057 * A117923 A117924 A374561
KEYWORD
nonn,base
AUTHOR
Rémy Sigrist, Apr 27 2024
STATUS
approved