You are viewing a single comment's thread. Return to all comments →
Python 3:
def andProduct(a, b): if a == 0: return 0 if a == b: return a out = None if a % 2 == 0 else a if out is not None: a+=1 temp = a def check_less_significant_bits(num): shift = 0 zero=True cum_sum=0 n_sum=0 while zero: zero = (num & ( 1 << shift )) == 0 if zero: cum_sum += 2**shift shift+=1 return cum_sum + 1 a += check_less_significant_bits(a) while a <= b: temp &= a if temp == 0: return 0 inc = check_less_significant_bits(a) a+=inc if out is not None: return temp & out return temp
Seems like cookies are disabled on this browser, please enable them to open this website
AND Product
You are viewing a single comment's thread. Return to all comments →
Python 3: