A362160 Irregular triangle read by rows: The n-th row contains 2^n integers corresponding to the words of the n-bit Gray code with the most significant bits changing fastest.
0, 0, 1, 0, 2, 3, 1, 0, 4, 6, 2, 3, 7, 5, 1, 0, 8, 12, 4, 6, 14, 10, 2, 3, 11, 15, 7, 5, 13, 9, 1, 0, 16, 24, 8, 12, 28, 20, 4, 6, 22, 30, 14, 10, 26, 18, 2, 3, 19, 27, 11, 15, 31, 23, 7, 5, 21, 29, 13, 9, 25, 17, 1, 0, 32, 48, 16, 24, 56, 40, 8, 12, 44, 60, 28
Offset: 0
Examples
Triangle begins: k = 0 1 2 3 4 5 6 7 ... n=0: 0, n=1: 0, 1, n=2: 0, 2, 3, 1, n=3: 0, 4, 6, 2, 3, 7, 5, 1, n=4: 0, 8, 12, 4, 6, 14, 10, 2, 3, 11, 15, 7, 5, 13, 9, 1, n=5: 0, 16, 24, 8, 12, 28, 20, 4, 6, 22, 30, 14, 10, 26, 18, 2, 3, 19, 27, 11, 15, 31, 23, 7, 5, 21, 29, 13, 9, 25, 17, 1, ... In row n=3, the corresponding binary words of length 3 are 000, 100, 110, 010, 011, 111, 101, and 001 - notice that the most significant bits change the fastest.
References
- W. Lipski Jr, Combinatorics for programmers, Mir, Moscow, 1988, (in Russian), p. 31, Algorithm 1.13.
- F. Ruskey, Combinatorial Generation. Working Version (1j-CSC 425/520), 2003, pp. 120-121.
Links
- Valentin Bakoev, Rows n = 0..15, flattened
- Valentin Bakoev, Mirror (left-recursive) Gray Code, Mathematics and Informatics, Vol. 66, Number 6, pp. 559-578, (2023).
Crossrefs
Programs
-
Maple
with(ListTools): with(Bits): T:= (n, k)-> Join(Reverse(Split(Xor(k, iquo(k, 2)), bits=n))): seq(seq(T(n, k), k=0..2^n-1), n=0..6); # Alois P. Heinz, Jun 05 2023
-
PARI
T(n,k) = fromdigits(Vecrev(binary(bitxor(k,k>>1)), n), 2); \\ Kevin Ryde, Apr 17 2023
Formula
T(n,k) = 2*T(n-1,k) for 0 <= k < 2^(n-1), and
T(n,2^(n-1)+k) = 2*T(n-1,2^(n-1)-k-1) + 1 = T(n,2^(n-1)-k-1) + 1 for 0 <= k < 2^(n-1).
T(n,k+1) = T(n,k) XOR 2^(n-A001511(k)).
T(n, k) = A088208(n, k) - 1. - Andrey Zabolotskiy, Dec 06 2024
Comments