Binary Strings

232 days ago by pdraznik

def getBin(stringlen, conseclen): "Set Binary String length and number of consecutive numbers you want, program responds with how many strings there are of the given length that don't have the consecutive numbers and then with how many do" i = 0 bit = [] while(i < stringlen): if(i<conseclen - 1): bit = bit + [2**(i+1)] elif(i==conseclen - 1): bit = bit + [(2**(i+1)) - 1] else: x = 1 b = 0 while(x<=conseclen): b = b + bit[i-x] x = x+1 bit = bit + [b] i = i + 1 print("aren't: ") print(bit[i - 1]) print("are: ") print(2**i - bit[i-1]) print("percent that are: ") print( (1.0 -(bit[i-1]/2**i)) * 100) 
       
getBin(44,5) 
       
aren't: 
8739089177552
are: 
8853096866864
percent that are: 
50.3240293418457
aren't: 
8739089177552
are: 
8853096866864
percent that are: 
50.3240293418457