OFFSET
0,3
COMMENTS
A permutation of the nonnegative integers with inverse A379657.
LINKS
Rémy Sigrist, Table of n, a(n) for n = 0..10000
Joerg Arndt, Matters Computational (The Fxtbook), pages 61-62.
Wikipedia, Balanced ternary
Wikipedia, Non-adjacent form
EXAMPLE
The first terms are:
n a(n) naf(n) bter(a(n))
-- ---- ------ ----------
0 0 0 0
1 1 1 1
2 3 10 10
3 2 10T 1T
4 9 100 100
5 4 101 11
6 6 10T0 1T0
7 8 100T 10T
8 27 1000 1000
9 10 1001 101
10 12 1010 110
11 5 10T0T 1TT
12 18 10T00 1T00
PROG
(PARI) a(n) = { my (v = 0, t = 1, d); while (n, if (n%2, n -= d = 2 - (n%4); v += d*t; t /= 3; ); n \= 2; t *= 3; ); return (v); }
CROSSREFS
KEYWORD
nonn,base,new
AUTHOR
Rémy Sigrist, Dec 29 2024
STATUS
approved