3 ms·
An algorithm that works for any even n is to generate the Gray code for the next highest power of 2 (in this case, 16) then pick the middle n symbols. Eg the 1
by caf 10y ago
An algorithm that works for any even n is to generate the Gray code for the next highest power of 2 (in this case, 16) then pick the middle n symbols. Eg the 16 position Gray code, with the middle 12 symbols marked:
0000
0001
0011 <
0010 <
0110 <
0111 <
0101 <
0100 <
1100 <
1101 <
1111 <
1110 <
1010 <
1011 <
1001
1000