Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Bit manipulation without comments solution in Clear category for IP Network: Route Summarization by lezeroq
def checkio(data):
str2ip = lambda ip: sum(int(n)*(256**p) for p, n in enumerate(reversed(ip.split('.'))))
ip2str = lambda ip: '.'.join(str((ip & (1 << i) - 1) >> (i - 8)) for i in range(32, 0, -8))
ips = [str2ip(i) for i in data]
diff = min(ips) ^ max(ips)
subnet = 32
mask = (1 << 32) - 1
while diff:
diff >>= 1
mask <<= 1
subnet -= 1
return '%s/%d' % (ip2str(ips[0] & mask), subnet)
March 10, 2016