Check if bits of a number has count of consecutive set bits in increasing order | Returns true if n has increasing count of continuous - 1 else false ; store the bit - pattern of n into bit bitset - bp ; set prev_count = 0 and curr_count = 0. ; increment current count of continuous - 1 ; traverse all continuous - 0 ; check prev_count and curr_count on encounter of first zero after continuous - 1 s ; check for last sequence of continuous - 1 ; Driver code
def findContinuous1 ( n ) : NEW_LINE INDENT bp = list ( bin ( n ) ) NEW_LINE bits = len ( bp ) NEW_LINE prev_count = 0 NEW_LINE curr_count = 0 NEW_LINE i = 0 NEW_LINE while ( i < bits ) : NEW_LINE INDENT if ( bp [ i ] == '1' ) : NEW_LINE INDENT curr_count += 1 NEW_LINE i += 1 NEW_LINE DEDENT elif ( bp [ i - 1 ] == '0' ) : NEW_LINE INDENT i += 1 NEW_LINE curr_count = 0 NEW_LINE continue NEW_LINE DEDENT else : NEW_LINE INDENT if ( curr_count < prev_count ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT i += 1 NEW_LINE prev_count = curr_count NEW_LINE curr_count = 0 NEW_LINE DEDENT DEDENT if ( prev_count > curr_count and ( curr_count != 0 ) ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT return 1 NEW_LINE DEDENT n = 179 NEW_LINE if ( findContinuous1 ( n ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT