Post History
Python, 143 bytes def r(i): y,z=65537,1+(1<<32);s=257*y*z;n=(i|(i&252*s)*y>>10|(i&254*s)*z>>17|(i&127*s)*z>>15|(i&63*s)*y>>6)&(1<<64)-1 ...
Answer
#1: Initial revision
## Python, 143 bytes ```python def r(i): y,z=65537,1+(1<<32);s=257*y*z;n=(i|(i&252*s)*y>>10|(i&254*s)*z>>17|(i&127*s)*z>>15|(i&63*s)*y>>6)&(1<<64)-1 return 64-n.bit_count() ``` This is a port of trichoplax's Rust answer, written with relatively little comprehension. Because Python's integers are arbitrary sized, they cannot implicitly cut off bits above the least significant 64 bits (so we must explicitly mask the value afterwards); however, this also means that shifts beyond that point will preserve bits, which allows refactoring some pairs of shifts as a multiplication (which now cannot overflow) and shift. Since it's now required to multiply by some numbers that are factors of the magic constant `s` (equal to `0x1010101010101`), it's now computed as a product of those factors. Python's integer type does not provide a method to count clear bits, but it does provide a method to count *set* bits. Because of the need to assign and remember multiple values in order, this won't work directly as a `lambda`; using the `:=` operator is complex and seems unlikely to offer a net improvement.