login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

A334913
a(n) is the sum of digits of n in signed binary nonadjacent form.
2
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,6
LINKS
FORMULA
a(n) = hammingweight(A184615(n)) - hammingweight(A184616(n)). - Joerg Arndt, Jun 13 2020
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