FM Algorithm Implemtation using Python

FM Algorithm Implementation using Python

 

 Source Code:

inp = list(map(int,raw_input("Enter Elements : ").split()))
max_ct = 0
for n in inp:
    v = (6*n+1)%5
    ct = 0
    converted = bin(v).replace("0b","")
    for i in converted[::-1]:
        if(i!='1'):
            ct = ct+1
        if(len(converted) == ct):
            ct = 0
        if(ct>max_ct):
            max_ct = ct

print "Number of Distinct Element = ",2**max_ct


Output:
Enter Elements : 153 45 10 36 20 10 36 45 20
Number of Distinct Element =  4

Comments