OFFSET
0,3
COMMENTS
As the graph demonstrates, the sequence makes large negative steps at terms (3^i+1)/2. These steps divide the graph into conspicuous blocks. - N. J. A. Sloane, Jul 03 2016
REFERENCES
D. E. Knuth, The Art of Computer Programming, Addison-Wesley, Reading, MA, Vol 2, pp 173-175.
LINKS
Reinhard Zumkeller, Table of n, a(n) for n = 0..10000
Eric Weisstein's World of Mathematics, Reversal
Wikipedia, Balanced Ternary
EXAMPLE
20 = 1*3^3 - 1*3^2 + 1*3^1 - 1*3^0 == '+-+-'
=> a(20) = -1*3^3 + 1*3^2 - 1*3^1 + 1*3^0 = -20;
21 = 1*3^3 - 1*3^2 + 1*3^1 + 0*3^0 == '+-+0'
=> a(21) = 0*3^3 + 1*3^2 - 1*3^1 + 1*3^0 = 7;
22 = 1*3^3 - 1*3^2 + 1*3^1 + 1*3^0 == '+-++'
=> a(22) = 1*3^3 + 1*3^2 - 1*3^1 + 1*3^0 = 34;
23 = 1*3^3 + 0*3^2 - 1*3^1 - 1*3^0 == '+0--'
=> a(23) = -1*3^3 - 1*3^2 + 0*3^1 + 1*3^0 = -35;
24 = 1*3^3 + 0*3^2 - 1*3^1 + 0*3^0 == '+0-0'
=> a(24) = 0*3^3 - 1*3^2 + 0*3^1 + 1*3^0 = -8;
25 = 1*3^3 + 0*3^2 - 1*3^1 + 1*3^0 == '+0-+'
=> a(25) = 1*3^3 - 1*3^2 + 0*3^1 + 1*3^0 = 19.
PROG
(Python)
def a(n):
if n==0: return 0
s=[]
x=0
while n>0:
x=n%3
n=n//3
if x==2:
x=-1
n+=1
s.append(x)
l=s[::-1]
return sum(l[i]*3**i for i in range(len(l)))
print([a(n) for n in range(101)]) # Indranil Ghosh, Jun 10 2017
CROSSREFS
KEYWORD
AUTHOR
Reinhard Zumkeller, Oct 19 2007
STATUS
approved