Misère Nim

  • + 0 comments
    def misereNim(s):
        if all(x == 1 for x in s):
            if len(s) % 2 == 1:
                return "Second"
            else:
                return "First"
        else:
            balance = 0
            for val in s:
                balance ^= val
            if balance == 0:
                return "Second"
            else:
                return "First"