Solutions for Consecutive 1's

    • @GarretVam
    • @mason, submitted in Python 2, achived 100% score
    def solve(x):
    
        # Initialize result
        count = 0
    
        # Count the number of iterations to
        # reach x = 0.
        while (x!=0):
    
            # This operation reduces length
            # of every sequence of 1s by one.
            x = (x & (x << 1))
    
            count=count+1
    
        return count
    
    
    • @GarretVam
    • @mason, submitted in Python 2, achived 100% score
    def solve(x):
    
        # Initialize result
        count = 0
    
        # Count the number of iterations to
        # reach x = 0.
        while (x!=0):
    
            # This operation reduces length
            # of every sequence of 1s by one.
            x = (x & (x << 1))
    
            count=count+1
    
        return count
    
    
    • @GarretVam
    • @mason, submitted in Python 3, achived 100% score
    def solve(x):
    
        # Initialize result
        count = 0
    
        # Count the number of iterations to
        # reach x = 0.
        while (x!=0):
    
            # This operation reduces length
            # of every sequence of 1s by one.
            x = (x & (x << 1))
    
            count=count+1
    
        return count