OFFSET
0,2
COMMENTS
The above observation follows because by definition, a(n) gives the Hamming distance between binary expansions of n and A003188(3+A006068(n)). To see how this leads to the stated claim, consider the illustration "Visualized as a traversal of vertices of a tesseract" in the Wikipedia article "Gray code". Starting from any vertex with either (A) an even, or (B) an odd number of 1-bits, traverse three edges along the red path, to the direction indicated by the arrow, and then note the Hamming distance between the starting and the ending vertex. It is always 1 in case (A), and 3 in case (B), because the position of the flipped bit is given by sequence A007814, with its every other term zero, so in case (A) the third flip cancels the first flip (both toggling the rightmost bit), which leaves only the second bit-flip effective. Note that the properties of a tesseract generalize to those of an infinite dimensional hypercube. - Antti Karttunen, Mar 11 2024
LINKS
Antti Karttunen, Table of n, a(n) for n = 0..8191
Wikipedia, Gray code.
FORMULA
a(n) = A101080(n,A268823(3+n)), where A101080(x,y) gives the Hamming distance between binary expansions of x and y.
a(n) = 1 + 2 * A010060(n). - Joerg Arndt, Mar 11 2024
MAPLE
a := n -> 2-(-1)^add(convert(n, base, 2)):
seq(a(n), n = 0 .. 120); # Lorenzo Sauras Altuzarra, Mar 10 2024
PROG
;; Where A101080bi implements the dyadic function A101080(x, y) which gives the Hamming distance between binary expansions of x and y.
(PARI)
A003188(n) = bitxor(n, n>>1);
A006068(n) = { my(s=1, ns); while(1, ns = n >> s; if(0==ns, return(n)); n = bitxor(n, ns); s <<= 1); };
(PARI) A268676(n) = 2-((-1)^hammingweight(n)); \\ Antti Karttunen, Mar 11 2024, after Lorenzo Sauras Altuzarra's Maple-code.
CROSSREFS
KEYWORD
nonn
AUTHOR
Antti Karttunen, Feb 19 2016
STATUS
approved