I have tried this code in python can one tell me is this the right solution for king kohima's problem def binary(i): r=str(0) while(i): x=str(i%2) if(x=='1' and r[-1]=='1'): return None else: r=r+str(x) i=i/2 return r m=3 l=[] for i in range(0,2**m): l.append(binary(i)) print(l) c=0 for i in l: if i: c=c+1 print(c*c)