Counter game

  • + 0 comments

    Javascript

    function counterGame(n) {
        // Write your code here    
        var turn = 0
        while(n > 1){
            n = Math.log2(n) % 1 == 0 ? n/2 : n - Math.pow(2, Math.floor(Math.log2(n)))        
            turn ++
        }
        return turn % 2 == 0 ? 'Richard' : 'Louise'
    }