Misère Nim

  • + 0 comments

    If you're familiar with Nim-Sum, this problem will be very easy; otherwise, it's incredibly difficult. This type of problem should be used to test well-read individuals, not programmers.

        let allOnes = true;
        
        for (let stone of stones) {
            xorSum ^= stone;
            if (stone > 1) {
                allOnes = false;
            }
        }
        
        if (allOnes) {
            return stones.length % 2 === 0 ? "First" : "Second";
        } else {
            return xorSum === 0 ? "Second" : "First";
        }