Counter game

  • + 0 comments

    Python:

    def counterGame(n):
        moves = 0
        
        while n != 1:
    
            exponent = math.log2(n)
            if exponent.is_integer():
                n = n/2
            else:
                n = n - 2 ** int(exponent)
            moves += 1