In this Kata you need to write the method SharedBits that returns true if 2 integers share at least two '1' bits. For simplicity assume that all numbers are positive

For example
int seven = 7;    //0111
int ten = 10;     //1010
int fifteen = 15; //1111
SharedBits(seven, ten);     //false
SharedBits(seven, fifteen); //true
SharedBits(ten, fifteen);   //true

- seven and ten share only a single '1' (at index 3)
- seven and fifteen share 3 bits (at indexes 1, 2, and 3)
- ten and fifteen  share 2 bits (at indexes 0 and 2)

Hint: you can do this with just string manipulation, but binary operators will make your life much easier.

Difficulty: introductory

Starter code:

def shared_bits(a, b):
	

Solutions:
def shared_bits(a, b):
    return bin(a & b).count('1') > 1

def shared_bits(a, b):
    return bool(a & b & (a & b) - 1)

def shared_bits(a, b):
    num = a & b
    count = bin(num).count("1")
    if count >= 2:
        return True
    return False

def shared_bits(a, b):
    return len(bin(a&b).strip('0b0'))>1

def shared_bits(a, b):
    return f"{a & b:b}".count("1") > 1

def shared_bits(a, b):
    return a & b and bin(a & b).count("1") > 1

def shared_bits(a, b): ###
    return bin(a&b).count('1')>1

def shared_bits(a, b):
    res=0
    bina,binb='{:b}'.format(a),'{:b}'.format(b)
    bina,binb=bina.zfill(max(len(bina),len(binb))),binb.zfill(max(len(bina),len(binb)))
    for x,y in zip(bina,binb):
        if x==y=='1':
            res+=1
            if res==2:
                return True
    return False

def shared_bits(a, b):
    bina,binb='{:011b}'.format(a),'{:011b}'.format(b)
    return sum(1 for x,y in zip(bina,binb) if x==y=='1')>=2

def shared_bits(a, b):
    count = 0
    lst_a = list("{0:b}".format(a))
    lst_b = list("{0:b}".format(b))
    lst_a.reverse()
    lst_b.reverse()
    n_a = len(lst_a)
    n_b = len(lst_b)
    if(n_a == 0 or n_b == 0):
        return False
    else:
        if(n_a <= n_b):
            for i in range(n_a):
                if(lst_a[i] == lst_b[i] and lst_a[i] == "1"):
                    count += 1
                    if(count == 2):
                        return True
            return False
        else:
            for i in range(n_b):
                if(lst_a[i] == lst_b[i] and lst_b[i] == "1"):
                    count += 1
                    if(count == 2):
                        return True
            return False

def shared_bits(a, b):
    if a > b:
        c=a
        a=b
        b=c 
    a_bin = str(bin(a))
    b_bin = str(bin(b))
    count = 0
    for i in range(len(a_bin)-1,1,-1):
        if a_bin[i] == '1' and a_bin[i]==b_bin[i+len(b_bin)-len(a_bin)]:
            count += 1
    if count >= 2:
        return True
    else:
        return False

def shared_bits(a, b):
    
    x = "{0:016b}".format(min(a,b))
    y = "{0:016b}".format(max(a,b))
    sol=0
    
    for i in range(len(x)):
        if x[i] == "1" and y[i] == "1":
            sol+=1
    
    return sol>=2

def shared_bits(a, b):
    a = bin(a)
    b = bin(b)
    n = 0
    for i in range(1, min(len(a), len(b))):
        if a[-i] == b[-i] and a[-i] == '1':
            n += 1
    return n >= 2

def shared_bits(a, b):
    bin_a = bin(a)[2:]
    bin_b = bin(b)[2:]
    
    if len(bin_a) > len(bin_b):
        bin_b = ('0' * (len(bin_a) - len(bin_b))) + bin_b 
    if len(bin_a) < len(bin_b):
        bin_a = ('0' * (len(bin_b) - len(bin_a))) + bin_a

    index = 0
    counter = 0
    while index < len(bin_a):
        if bin_a[index] == '1' and bin_b[index] == '1':
            counter += 1

        if counter >= 2:
            return True
        
        index += 1
    
    return False

def shared_bits(a, b):
    return sum(ai == bi == '1' for ai, bi in zip(f"{a:b}"[::-1], f"{b:b}"[::-1])) >= 2

def shared_bits(a, b):
    return True if format(a & b, 'b').count('1') > 1 else False

def shared_bits(a, b):
    a = bin(a)[2:]
    b = bin(b)[2:]
    if len(a) > len(b):
        b = b.zfill(len(a))
    else:
        a = a.zfill(len(b))
    
    a = list(a)
    b = list(b)
    
    return [x+y for x,y in zip(a,b)].count('11')>1

shared_bits = lambda a, b: sum(f"{a:16b}"[i] == f"{b:16b}"[i] == "1" for i in range(16)) > 1

def shared_bits(a, b):
    counter = 0
    for x in range(0, max(a, b)+1):
        if a & pow(2, x) and b & pow(2, x):
            counter += 1
            if counter >= 2:
                return True
    return False
   
    
    
    


def shared_bits(a, b):
    result = b & a
    commun = 0
    
    for i in range(0, 17):
        if (result & pow(2,i)) != 0:
            commun += 1
    if commun >= 2:
        return True
    else:
        return False
    return