bits − 1 around a circle so that any two neighbours (including the last and the first) differ in exactly one bit. We use the **mirror order** for that:
- for 1 bit it is 0, 1;
- the order for b bits is built from the order for b − 1 bits: first that order itself, then the same numbers in reverse with bit b − 1 (the new top bit) switched on.
For example, 2 bits give 0, 1, 3, 2.
Return the 2^bits numbers in mirror order, rotated around the circle so that the list starts with start.bits=2, start=1 → [1, 3, 2, 0]
The mirror order for 2 bits is 00, 01, 11, 10, i.e. 0, 1, 3, 2. Starting from 1 and wrapping around gives 1, 3, 2, 0. Every neighbouring pair, including 0 and 1 at the seam, differs in one bit.
bits=3, start=6 → [6, 7, 5, 4, 0, 1, 3, 2]
For 3 bits, take 0, 1, 3, 2 and append the same values in reverse with the top bit set: 6, 7, 5, 4. That gives 0, 1, 3, 2, 6, 7, 5, 4, rotated so that 6 comes first.
bits=1, start=0 → [0, 1]
bits ≤ 16start < 2^bitsbits=2, start=1
[1, 3, 2, 0]
Run checks the first 3 tests in your browser. Submit checks all 58 tests on the server, hidden ones included.