|
|
A059095
|
|
List consisting of the representation of n in base 3 using digits -1, 0, 1.
|
|
27
|
|
|
1, 1, -1, 1, 0, 1, 1, 1, -1, -1, 1, -1, 0, 1, -1, 1, 1, 0, -1, 1, 0, 0, 1, 0, 1, 1, 1, -1, 1, 1, 0, 1, 1, 1, 1, -1, -1, -1, 1, -1, -1, 0, 1, -1, -1, 1, 1, -1, 0, -1, 1, -1, 0, 0, 1, -1, 0, 1, 1, -1, 1, -1, 1, -1, 1, 0, 1, -1, 1, 1, 1, 0, -1, -1, 1, 0, -1, 0, 1, 0, -1, 1, 1, 0, 0, -1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, -1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, -1, -1
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
OFFSET
|
1
|
|
COMMENTS
|
Every natural number n has a unique representation as n = Sum_{i=1..k} e(i)*(3^i) for some k where e(i) is one of -1,0,1. Example: 25 = 27-3+1 = 1*3^3+0*3^2+(-1)*3^1+1*3^0 so its representation is 1,0,-1,1. So by writing n in this base 3 representation and juxtaposing we get the sequence: (1), (1,-1), (1,0), (1,1), (1,-1,-1), ...
|
|
REFERENCES
|
D. E. Knuth, The Art of Computer Programming, Addison-Wesley, Reading, MA, Vol 2, pp 173-175.
|
|
LINKS
|
|
|
FORMULA
|
|
|
EXAMPLE
|
First 27 rows, with terms aligned with powers of 3:
3^3 3^2 3^1 3^0
--------------------
1: 1;
2: 1, -1;
3: 1, 0;
4: 1, 1;
5: 1, -1, -1;
6: 1, -1, 0;
7: 1, -1, 1;
8: 1, 0, -1;
9: 1, 0, 0;
10: 1, 0, 1;
11: 1, 1, -1;
12: 1, 1, 0;
13: 1, 1, 1;
14: 1, -1, -1, -1;
15: 1, -1, -1, 0;
16: 1, -1, -1, 1;
17: 1, -1, 0, -1;
18: 1, -1, 0, 0;
19: 1, -1, 0, 1;
20: 1, -1, 1, -1;
21: 1, -1, 1, 0;
22: 1, -1, 1, 1;
23: 1, 0, -1, -1;
24: 1, 0, -1, 0;
25: 1, 0, -1, 1;
26: 1, 0, 0, -1;
27: 1, 0, 0, 0;
... (End)
|
|
MATHEMATICA
|
Array[If[First@ # == 0, Rest@ #, #] &[Prepend[IntegerDigits[#, 3], 0] //. {a___, b_, 2, c___} :> {a, b + 1, -1, c}] &, 32] // Flatten (* Michael De Vlieger, Jun 27 2020 *)
|
|
PROG
|
(Python)
def b3(n):
if n == 0: return []
carry, trailing = [(0, 0), (0, 1), (1, -1)][n % 3]
return b3(n//3 + carry) + [trailing]
t = []
for n in range(50):
t += b3(n)
print(t)
(PARI) row(n) = apply(d->d-1, digits(n + 3^(logint(n<<1, 3)+1)>>1, 3)); \\ Kevin Ryde, Mar 04 2022
|
|
CROSSREFS
|
|
|
KEYWORD
|
tabf,sign,easy
|
|
AUTHOR
|
Avi Peretz (njk(AT)netvision.net.il), Feb 13 2001
|
|
EXTENSIONS
|
More terms from Larry Reeves (larryr(AT)acm.org), Jul 20 2001
|
|
STATUS
|
approved
|
|
|
|