OFFSET
0,6
COMMENTS
The entry at row n, column k, gives the Hamming distance between binary expansions of k and A003188(n+A006068(k)). When Gray code is viewed as a traversal of vertices of an infinite dimensional hypercube by bit-flipping (see the illustration "Visualized as a traversal of vertices of a tesseract" in the Wikipedia's "Gray code" article) the argument k is the "address" (the binary code given inside each vertex) of the starting vertex, and argument n tells how many edges forward along the Gray code path we should hop from it (to the direction that leads away from the vertex with code 0000...). A(n, k) gives then the Hamming distance between the starting and the ending vertex. For how this works with case n=3, see comments in A268676. - Antti Karttunen, Mar 11 2024
LINKS
Wikipedia, Gray code.
FORMULA
EXAMPLE
The top left [0 .. 24] X [0 .. 24] section of the array:
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
1, 3, 3, 1, 3, 1, 1, 3, 3, 1, 1, 3, 1, 3, 3, 1, 3, 1, 1, 3, 1, 3, 3, 1, 1
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
3, 1, 3, 3, 3, 3, 3, 1, 3, 3, 3, 1, 3, 1, 3, 3, 3, 3, 3, 1, 3, 1, 3, 3, 3
2, 2, 4, 4, 4, 4, 2, 2, 4, 4, 2, 2, 2, 2, 4, 4, 4, 4, 2, 2, 2, 2, 4, 4, 2
1, 3, 3, 3, 3, 3, 1, 3, 3, 3, 1, 3, 1, 3, 3, 3, 3, 3, 1, 3, 1, 3, 3, 3, 1
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
3, 3, 1, 3, 3, 3, 3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, 3, 3, 3, 1, 3, 5, 5, 3, 5, 3, 5, 5, 5, 5, 5, 3, 5, 3, 5, 5, 5, 3
2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2
MATHEMATICA
A101080[n_, k_]:= DigitCount[BitXor[n, k], 2, 1]; A003188[n_]:=BitXor[n, Floor[n/2]]; A006068[n_]:=If[n<2, n, Block[{m=A006068[Floor[n/2]]}, 2m + Mod[Mod[n, 2] + Mod[m, 2], 2]]]; a[r_, 0]:= 0; a[0, c_]:=c; a[r_, c_]:= A003188[1 + A006068[a[r - 1, c - 1]]]; A[r_, c_]:=A101080[c, a[r, r + c]]; Table[A[c, r - c], {r, 0, 20}, {c, 0, r}] // Flatten (* Indranil Ghosh, Apr 02 2017 *)
PROG
(Scheme)
(define (A268833bi row col) (A101080bi col (A268820bi row (+ row col))))
(PARI) b(n) = if(n<1, 0, b(n\2) + n%2);
A101080(n, k) = b(bitxor(n, k));
A003188(n) = bitxor(n, n\2);
for(r=0, 20, for(c=0, r, print1(A(c, r - c), ", "); ); print(); ) \\ Indranil Ghosh, Apr 02 2017
(PARI)
A268833list(up_to) = { my(v = vector(up_to), i=0); for(a=0, oo, for(col=0, a, i++; if(i > up_to, return(v)); v[i] = A268833sq(a-col, col))); (v); };
v268833 = A268833list(1+up_to);
A268833(n) = v268833[1+n]; \\ Antti Karttunen, Mar 11 2024
(Python)
def A101080(n, k): return bin(n^k)[2:].count("1")
def A003188(n): return n^(n//2)
def A006068(n):
if n<2: return n
else:
m=A006068(n//2)
return 2*m + (n%2 + m%2)%2
for r in range(21):
print([a(c, r - c) for c in range(r + 1)]) # Indranil Ghosh, Apr 02 2017
KEYWORD
nonn,tabl
AUTHOR
Antti Karttunen, Feb 15 2016
EXTENSIONS
Definition simplified by Antti Karttunen, Mar 11 2024
STATUS
approved