Python, Functional style
We write a function apply that takes two sets of possibilities for A and B and returns all possible results operator(A, B) or operator(B, A) for all possible op
We write a function `apply` that takes two sets of possibilities for A and B and returns all possible results `operator(A, B)` or `operator(B, A)` for all possible operators.\n\nIgnoring reflection, there are only two ways we can apply the operators: (AB)(CD) or ((AB)C)D.  When C and D are ordered, this becomes three ways - the third way is ((AB)D)C.\n\nThis solution is a little slow because it has to manage sets - my article has a solution that is almost 10x faster.  I think this one is cool though.\n\n```\ndef judgePoint24(self, nums):\n    from operator import truediv, mul, add, sub\n    from fractions import Fraction\n\n    def apply(A, B):\n        ans = set()\n        for x, y, op in itertools.product(A, B, (truediv, mul, add, sub)):\n            if op is not truediv or y: ans.add(op(x, y))\n            if op is not truediv or x: ans.add(op(y, x))\n        return ans\n    \n    A = [{x} for x in map(Fraction, nums)]\n    for i, j in itertools.combinations(range(4), 2):\n        r1 = apply(A[i], A[j])\n        k, l = {0, 1, 2, 3} - {i, j}\n        if 24 in apply(apply(r1, A[k]), A[l]): return True\n        if 24 in apply(apply(r1, A[l]), A[k]): return True\n        if 24 in apply(r1, apply(A[k], A[l])): return True\n    \n    return False\n```
[]