OFFSET
0,3
COMMENTS
Leading zeros in ternary expansions are ignored.
This sequence is a self-inverse permutation of the nonnegative integers.
LINKS
EXAMPLE
The first terms, in decimal and in ternary, are:
n a(n) ter(n) ter(a(n))
-- ---- ------ ---------
0 0 0 0
1 1 1 1
2 2 2 2
3 5 10 12
4 4 11 11
5 3 12 10
6 7 20 21
7 6 21 20
8 8 22 22
9 17 100 122
10 16 101 121
11 15 102 120
12 14 110 112
13 13 111 111
14 12 112 110
15 11 120 102
PROG
(PARI) a(n) = { my (d = digits(n, 3), m); if (#d==0, m = [0, 1, 2], d[1]==1, m = [2, 1, 0], m = [1, 0, 2]); fromdigits(apply(t -> m[1+t], d), 3); }
CROSSREFS
KEYWORD
nonn,base,easy
AUTHOR
Rémy Sigrist, Mar 31 2023
STATUS
approved