You are viewing a single comment's thread. Return to all comments →
if name == 'main': n = int(input().strip())
n_bin = bin(n) n_bin = bin(n) max_consecutive = 0 count_consecutive1 = 0 count_consecutive0 = 0 for i in n_bin: if i == '1': count_consecutive1 += 1 if count_consecutive1 > max_consecutive: max_consecutive = count_consecutive1 elif i == '0': count_consecutive1 = 0 count_consecutive0 += 1 if count_consecutive0 > max_consecutive: max_consecutive = count_consecutive0 else: count_consecutive1 = 0 count_consecutive0 = 0 print(max_consecutive)
Seems like cookies are disabled on this browser, please enable them to open this website
Day 10: Binary Numbers
You are viewing a single comment's thread. Return to all comments →
if name == 'main': n = int(input().strip())