Created
August 10, 2022 14:58
-
-
Save sairamdgr8/d4664cebcfeab0e3439e1ca299ad35bb to your computer and use it in GitHub Desktop.
Sai-Working-find the biggest consecitve series from binary code -using-python.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print("Input the binary code of 1's and 0's") | |
s=input(str()) | |
print("Please press 1 or 0 to get their biggest series") | |
choose=input(str()) | |
list_s=[] | |
list_1=[] | |
list_2=[] | |
for i_1 in s: | |
list_s.append(i_1) | |
list_s_index=[] | |
len(list_s) | |
for i_2 in range(0,len(list_s)): | |
list_s_index.append(i_2) | |
dict_from_list = dict(zip(list_s_index,list_s)) | |
for key,value in dict_from_list.items(): | |
if value =='1': | |
list_1.append(key) | |
else: | |
list_2.append(key) | |
if choose=='1': | |
seq=list_1 | |
else: | |
seq=list_2 | |
def group_by_missing(seq): | |
if not seq: | |
return seq | |
grouped = [[seq[0]]] | |
for x in seq[1:]: | |
if x == grouped[-1][-1] + 1: | |
grouped[-1].append(x) | |
else: | |
grouped.append([x]) | |
return grouped | |
grouped_list=group_by_missing(seq) | |
grouped_list_len=[] | |
for i_3 in grouped_list: | |
grouped_list_len.append(len(i_3)) | |
max_num=max(grouped_list_len) | |
all_max_num=[] | |
for i_4 in grouped_list_len: | |
if i_4==max_num: | |
all_max_num.append(i_4) | |
o=[] | |
for i_5 in grouped_list: | |
if len(i_5)==max_num: | |
o.append((min(i_5),max(i_5),len(i_5))) | |
print("There are {0} series ".format(len(o))) | |
for i_6,j,k in o: | |
print("Index starting at",i_6,"and ending with",j,"index and it's length is",k) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment