cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A372318 For any n > 0, reverse digits in blocks in balanced ternary expansion of n where blocks are separated by 1's; a(0) = 0.

Original entry on oeis.org

0, 1, 2, 3, 4, 5, 8, 7, 6, 9, 10, 11, 12, 13, 14, 23, 16, 17, 26, 25, 20, 21, 22, 15, 24, 19, 18, 27, 28, 29, 30, 31, 32, 35, 34, 33, 36, 37, 38, 39, 40, 41, 68, 43, 50, 77, 70, 47, 48, 49, 44, 71, 52, 53, 80, 79, 74, 75, 76, 59, 62, 61, 60, 63, 64, 65, 66, 67
Offset: 0

Views

Author

Rémy Sigrist, Apr 27 2024

Keywords

Comments

This sequence is a self-inverse permutation of the nonnegative integers.
This sequence has infinitely many fixed points (A005836, among others).

Examples

			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.
		

Crossrefs

See A372317 for a similar sequence.
Cf. A005836.

Programs

  • 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); }