2^bits sectors, and each sector carries a code from 0 to 2^bits - 1. So the sensor never misreads at a border, the codes of neighboring sectors (including the last and the first) must differ in exactly one bit.
Such a sequence is built by mirroring:
1. start with the list [0];
2. for each bit k = 0, 1, …, bits - 1, append the current list in reverse order with bit k switched on in every number.
Return the resulting list of 2^bits numbers in exactly this order.bits=2 → [0, 1, 3, 2]
Start with [0]. Bit 0: the mirror of [0] with bit 0 set gives [0, 1]. Bit 1: the mirror [1, 0] with bit 1 set gives [3, 2], so the result is [0, 1, 3, 2], or 00, 01, 11, 10 in binary.
bits=3 → [0, 1, 3, 2, 6, 7, 5, 4]
Append [0, 1, 3, 2] in reverse with bit 2 switched on: 2+4, 3+4, 1+4, 0+4.
bits=2
[0, 1, 3, 2]
Run checks the first 3 tests in your browser. Submit checks all 14 tests on the server, hidden ones included.