login
A380350
In the ternary expansion of n, from left to right: replace the second, fourth, sixth, etc. nonzero digit, says d, by 3-d.
4
0, 1, 2, 3, 5, 4, 6, 8, 7, 9, 11, 10, 15, 16, 17, 12, 13, 14, 18, 20, 19, 24, 25, 26, 21, 22, 23, 27, 29, 28, 33, 34, 35, 30, 31, 32, 45, 46, 47, 48, 50, 49, 51, 53, 52, 36, 37, 38, 39, 41, 40, 42, 44, 43, 54, 56, 55, 60, 61, 62, 57, 58, 59, 72, 73, 74, 75, 77
OFFSET
0,3
COMMENTS
This sequence is a self-inverse permutation of the nonnegative integers.
FORMULA
a(A380349(n)) = A380349(a(n)) = A004488.
{a(n), A380349(n)} = {A380351(n), A380352(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 "101210", and a(321) = 292.
PROG
(PARI) a(n) = { my (d = digits(n, 3), nz = 0); for (k = 1, #d, 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):
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, A380351 and A380352 for similar sequences.
Sequence in context: A337136 A361314 A366474 * A138606 A166013 A089864
KEYWORD
nonn,base,easy,new
AUTHOR
Rémy Sigrist, Jan 22 2025
STATUS
approved