Counter game

  • + 0 comments
    #Python 3
    def counterGame(n):
        turns = 0
        while n > 1:
            power = 1 << (n.bit_length() - 1) #uses bit length to quickly calculate the largest power of 2 <= n
            if n == power:
                n >>=1 #use a bit shift to quickly divide by 2
            else: 
                n -= power
            turns += 1
               
        return "Louise" if turns %2 != 0 else "Richard"