A334913 a(n) is the sum of digits of n in signed binary nonadjacent form.
0, 1, 1, 0, 1, 2, 0, 0, 1, 2, 2, -1, 0, 1, 0, 0, 1, 2, 2, 1, 2, 3, -1, -1, 0, 1, 1, -1, 0, 1, 0, 0, 1, 2, 2, 1, 2, 3, 1, 1, 2, 3, 3, -2, -1, 0, -1, -1, 0, 1, 1, 0, 1, 2, -1, -1, 0, 1, 1, -1, 0, 1, 0, 0, 1, 2, 2, 1, 2, 3, 1, 1, 2, 3, 3, 0, 1, 2, 1, 1, 2, 3, 3, 2
Offset: 0
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.
Programs
-
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}]
-
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