[Python] Infer from maximum sequence lengths
The first step is to consider each element after modulo 3.\n\nThis approach considers what is the maximum sequence length you can get from the stones.\n\nWe can
The first step is to consider each element after modulo 3.\n\nThis approach considers what is the maximum sequence length you can get from the stones.\n\nWe can assume there is no zeros for now.\n\nIf Alice starts with taking a one, to avoid getting 0 mod 3 the sequence is \n\n[1] 1 2 1 2 1 2 1 2 (... ending with 1 or 2)\n\nIf Alice starts with taking a two, to avoid getting 0 mod 3 the sequence is \n\n[2] 2 1 2 1 2 1 2 1 (... ending with 1 or 2)\n\nIf there are no ones or twos at the start, Alice cannot pick any stone and Bob wins.\nIf the sequence length is equal to the total number of stones, Bob wins (see question).\nIf the sequence length is odd, the last stone is taken by Alice, Alice wins.\nIf the sequence length is even, the last stone is taken by Bob, Bob wins.\n\nIf Alice can choose a winning sequence, Alice wins.\n\nHow do zeroes change the game?\n\nAfter Alice first takes the first one or two, either player can take a zero. The sequence length is simply extended by the number of zeroes.\n\n```python\nclass Solution:\n    def stoneGameIX(self, stones: List[int]) -> bool:\n        stones = [x%3 for x in stones]        \n        c = Counter(stones)\n        print()\n        print(c)\n\n        # 2 2 1 2 1 2 1 2 ... 0 0 0 0\n        \n        if c[2]:\n            len_sequence = c[0] + 1\n            c[2] -= 1\n            now_2 = True\n            while True:\n                if now_2:\n                    if c[2]:\n                        c[2] -= 1\n                        len_sequence += 1\n                    else:\n                        break\n                else:\n                    if c[1]:\n                        c[1] -= 1\n                        len_sequence += 1\n                    else:\n                        break\n                now_2 = not now_2\n                \n            print("start 2", len_sequence)\n            if len_sequence == len(stones):\n                pass\n            elif len_sequence%2:  # last stone drawn by alice\n                return True\n            \n        c = Counter(stones)\n            \n        if c[1]:\n            len_sequence = c[0] + 1\n            c[1] -= 1\n            now_1 = True\n            while True:\n                if now_1:\n                    if c[1]:\n                        c[1] -= 1\n                        len_sequence += 1\n                    else:\n                        break\n                else:\n                    if c[2]:\n                        c[2] -= 1\n                        len_sequence += 1\n                    else:\n                        break\n                now_1 = not now_1\n                \n            print("start 1", len_sequence)\n            if len_sequence == len(stones):\n                pass\n            elif len_sequence%2:  # last stone drawn by alice\n                return True\n\n            \n        # no ones and twos\n        return False\n```
[]