Python 3, simulation with remainders
Only divisibility is important. We can substitute each numberx with x%3.\nstones=[x%3 for x in stones]\n\nThen only numbers 0,1, and 2 would be in the array sto
Only divisibility is important. We can substitute each number```x``` with ```x%3```.\n```stones=[x%3 for x in stones]```\n\nThen only numbers ```0```,```1```, and ```2``` would be in the array ```stones```.\nWe can count each remainder.\nWe use array ```remainders``` as a counter.\nIt means: array ```stones``` contains ```remainders[0]``` numbers divisible by 3.\n\nStrategy ideas:\n0 doesn\'t change divisibility\ntake 1 if actualRemovedStones remainder is 1\ntake 2 if actualRemovedStones remainder is 2\n\nAlice starting first.\nIf Alice starts with 1, Bob can\'t take 2, he would be lost (1+2 is 3).\nIf Alice starts with 2, Bob can\'t take 1, he would be lost (2+1 is 3).\n\nWe are simulating the game with remainders only.\n```\nclass Solution:\n    def stoneGameIX(self, stones: List[int]) -> bool:\n        remainders=[0]*3\n        for x in stones:\n            remainders[x%3]+=1\n        \n        def play(s,r0,r1,r2,Alice):\n            if not sum([r0,r1,r2]):\n                return False\n            if s==1:\n                if r1:\n                    return play(2,r0,r1-1,r2,not Alice)\n                elif r0:\n                    return play(1,r0-1,r1,r2,not Alice)\n                else:\n                    return not Alice\n            elif s==2:\n                if r2:\n                    return play(1,r0,r1,r2-1,not Alice)\n                elif r0:\n                    return play(2,r0-1,r1,r2,not Alice)\n                else:\n                    return not Alice\n         \n        r0,r1,r2 = remainders\n        return r1 and play(1,r0,r1-1,r2,False) or r2 and play(2,r0,r1,r2-1,False)\n```
[]