4 ms·
Interesting! I didn't initially click to the fact that Harold's snippet was solving a different problem than the one previously talked about, so was confused wh
by akoboldfrying 3y ago
Interesting! I didn't initially click to the fact that Harold's snippet was solving a different problem than the one previously talked about, so was confused why it would "get stuck" flicking between two states after shrinking the rightmost run (of 1s or 0s), but that is indeed the desired behaviour if you want the nearest (not the next or previous) integer.
I actually found the author's complementing trick for getting the previous integer more interesting (because more applications):
>However since we already have a version that walks to the next we can simply apply a linear transform to map/unmap the input/result. The ones complement (~x) reverses the notion of unsigned integer ordering so the follow function walks to the previous