OFFSET
0,3
COMMENTS
All terms correspond to a sum of distinct powers of -3.
LINKS
Wyatt Powers, Table of n, a(n) for n = 0..9999
EXAMPLE
For n = 0, a(0) = 0.
for n = 1, a(1) = -3^0 = 1.
for n = 2, a(2) = -3^1 = -3.
for n = 3, a(3) = -3^1 + -3^0 = -2.
for n = 4, a(4) = -3^2 = 9.
for n = 5, a(5) = -3^2 + -3^0 = 10.
MATHEMATICA
(* Returns first 100 numbers in the sequence; assigned to the list, a *)
a = Table[IntegerDigits[x, 2], {x, 0, 100}];
For[i = 1, i <= Length[a], i++,
For[j = 1, j <= Length[a[[i]]], j++,
a[[i]][[j]] = ((a[[i]][[j]])*(-3)^(Length[a[[i]]] - j))
]
];
For[i = 1, i <= Length[a], i++, a[[i]] = Total[a[[i]]]];
a
PROG
(PARI) a(n) = my(b=Vecrev(binary(n))); sum(k=1, #b, b[k]*(-3)^(k-1)); \\ Michel Marcus, Mar 22 2021
(PARI) a(n) = fromdigits(binary(n), -3) \\ Kevin Ryde, Mar 22 2021
(Python)
def a(n):
return sum((-3)**k for k, b in enumerate(bin(n)[2:][::-1]) if b=='1')
print([a(n) for n in range(64)]) # Michael S. Branicky, Mar 23 2021
CROSSREFS
KEYWORD
AUTHOR
Wyatt Powers, Mar 21 2021
STATUS
approved