OFFSET
0,3
COMMENTS
To compute a(n): in the balanced ternary representation of n, replace each nonzero digit by "+1" and each nonleading zero by "-1".
LINKS
Rémy Sigrist, Table of n, a(n) for n = 0..6561
EXAMPLE
The first terms, alongside their balanced ternary representation (with "T" instead of digits "-1"), are:
n a(n) bter(n) bter(a(n))
-- ---- ------- ----------
0 0 0 0
1 1 1 1
2 4 1T 11
3 2 10 1T
4 4 11 11
5 13 1TT 111
6 11 1T0 11T
7 13 1T1 111
8 7 10T 1T1
9 5 100 1TT
10 7 101 1T1
11 13 11T 111
12 11 110 11T
13 13 111 111
14 40 1TTT 1111
15 38 1TT0 111T
PROG
(PARI) a(n) = if (n==0, 0, my (d=centerlift(Mod(n, 3))); if (d, +1, -1) + 3*a((n-d)\3))
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Rémy Sigrist, Apr 11 2021
STATUS
approved