• + 0 comments

    Ruby solution:

    def misereNim(s)
        # Write your code here
        total_xor = 0;
        total = 0;
    
        s.each_index do |i|
            total_xor ^= s[i];
            total += s[i];
        end
    
        if(s.size % 2 == 0)
            return s.size != total && total_xor == 0 ? "Second" : "First";
        else
            return s.size == total || total_xor == 0 ? "Second" : "First";
        end
    end