OFFSET
0,6
LINKS
Joerg Arndt, Matters Computational - Ideas, Algorithms, Source Code, 2011, Springer, pp. 61-62.
Helmut Prodinger, On binary representations of integers with digits -1,0,1, Integers 0 (2000), #A08.
FORMULA
MATHEMATICA
BBN[a_] := Module[{n = a, b}, b = IntegerDigits[n, 2]; b = Prepend[b, 0];
l = Length[b];
Do[If[b[[i]] == 2, b[[i]] = 0; b[[i - 1]]++,
If[b[[i]] == 1,
If[b[[i + 1]] == 1, b[[i - 1]]++; b[[i]] = 0;
b[[i + 1]] = -1]]], {i, l - 1, 2, -1}];
If[b[[1]] == 0, b = Delete[b, 1]]; b]
Table[a = BBN[i]; sod = 0; l = Length[a];
Do[sod = sod + a[[j]], {j, 1, l}]; sod, {i, 0, 83}]
PROG
(PARI)
bin2naf(x)=
{ /* Compute (nonadjacent) signed binary representation of x: */
local(xh, x3, c, np, nm);
xh = x >> 1;
x3 = x + xh;
c = bitxor(xh, x3);
np = bitand(x3, c); /* bits == +1 */
nm = bitand(xh, c); /* bits == -1 */
return([np, nm]); /* np-nm==x */
}
a(n) = my(b=bin2naf(n)); return(hammingweight(b[1])-hammingweight(b[2]));
vector(99, n, a(n-1)) \\ Joerg Arndt, Jun 13 2020
CROSSREFS
KEYWORD
base,easy,sign
AUTHOR
Lei Zhou, May 16 2020
STATUS
approved