close
login
A380352
In the ternary expansion of n, from right to left: replace the second, fourth, sixth, etc. nonzero digit, says d, by 3-d.
4
0, 1, 2, 3, 7, 8, 6, 4, 5, 9, 19, 20, 21, 16, 17, 24, 13, 14, 18, 10, 11, 12, 25, 26, 15, 22, 23, 27, 55, 56, 57, 34, 35, 60, 31, 32, 63, 46, 47, 48, 70, 71, 51, 67, 68, 72, 37, 38, 39, 79, 80, 42, 76, 77, 54, 28, 29, 30, 61, 62, 33, 58, 59, 36, 73, 74, 75, 43
OFFSET
0,3
COMMENTS
This sequence is a self-inverse permutation of the nonnegative integers.
FORMULA
a(A380351(n)) = A380351(a(n)) = A004488(n).
{a(n), A380351(n)} = {A380349(n), A380350(n)}.
a(n) = n iff n = 0 or n belongs to A038754.
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); forstep (k = #d, 1, -1, if (d[k], if (nz++%2==0, 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[::-1], 1):
if di != '0':
nz += 1
if nz&1 == 0: 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 A380349, A380350 and A380351 for similar sequences.
Sequence in context: A011027 A100072 A215722 * A324777 A244162 A182516
KEYWORD
nonn,base,easy
AUTHOR
Rémy Sigrist, Jan 22 2025
STATUS
approved