login
A380349
In the ternary expansion of n, from left to right: replace the first, third, fifth, etc. nonzero digit, says d, by 3-d.
4
0, 2, 1, 6, 7, 8, 3, 4, 5, 18, 19, 20, 21, 23, 22, 24, 26, 25, 9, 10, 11, 12, 14, 13, 15, 17, 16, 54, 55, 56, 57, 59, 58, 60, 62, 61, 63, 65, 64, 69, 70, 71, 66, 67, 68, 72, 74, 73, 78, 79, 80, 75, 76, 77, 27, 28, 29, 30, 32, 31, 33, 35, 34, 36, 38, 37, 42, 43
OFFSET
0,2
COMMENTS
This sequence is a self-inverse permutation of the nonnegative integers.
FORMULA
a(A380350(n)) = A380350(a(n)) = A004488.
{a(n), A380350(n)} = {A380351(n), A380352(n)}.
EXAMPLE
The ternary expansion of 321 is "102220", so the ternary expansion of a(321) is "202120", and a(321) = 555.
PROG
(PARI) a(n) = { my (d = digits(n, 3), nz = 0); for (k = 1, #d, if (d[k], if (nz++%2==1, d[k] = 3-d[k]; ); ); ); fromdigits(d, 3); }
(Python)
from gmpy2 import digits
def a(n):
d, nz = list(digits(n, 3)), 0
for i, di in enumerate(d):
if di != '0':
nz += 1
if nz&1: d[i] = '2' if di == '1' else '1'
return int("".join(d), 3)
print([a(n) for n in range(68)]) # Michael S. Branicky, Jan 24 2025
CROSSREFS
See A380350, A380351 and A380352 for similar sequences.
Cf. A004488.
Sequence in context: A244647 A324037 A160348 * A047708 A256277 A252746
KEYWORD
nonn,base,easy
AUTHOR
Rémy Sigrist, Jan 22 2025
STATUS
approved