• + 0 comments
    string nimGame(const vector<int>& pile) {
        int XOR = 0, twoOrMore = 0;
        for (int x : pile) {
            XOR = XOR ^ x;
            if (x > 1) twoOrMore++;
        }
        if (twoOrMore > 1) return (XOR == 0) ? "Second" : "First";
        else if (twoOrMore == 1) return "First";
        else return (pile.size() % 2 == 0) ? "First" : "Second";
    }