The solution to the Closest Integer with Same Weight problem suggests that “This approach works because we want to change bits that are as far to the right as possible.” However, the previous example, (in the case where 1110 is not closer in weight than 1011 to 111) contradicts this (1011 has the fourth and third rightmost bit changed, whereas 1110 has the fourth and first rightmost bit changed).
Can anyone give a more specific justification for why the solution (swapping the first set of consecutive bits that differ) is correct?
I’m reading version 1.5.1 btw