Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second solution in Speedy category for Binary Count by RRRQ
def checkio(number):
cnt = 0
while number:
num32 = number & 0xFFFFFFFF
number = number >> 32
a = (num32 & 0xAAAAAAAA) >> 1
b = (num32 & 0x55555555)
num32 = a + b
a = (num32 & 0xCCCCCCCC) >> 2
b = (num32 & 0x33333333)
num32 = a + b
a = (num32 & 0xF0F0F0F0) >> 4
b = (num32 & 0x0F0F0F0F)
num32 = a + b
a = (num32 & 0xFF00FF00) >> 8
b = (num32 & 0x00FF00FF)
num32 = a + b
a = (num32 & 0xFFFF0000) >> 16
b = (num32 & 0x0000FFFF)
num32 = a + b
cnt += num32
return cnt
Feb. 21, 2014
Comments: