Clean C++ solution using Rational class
c++\nclass Rational {\npublic:\n    Rational() {}\n    Rational(int num) : Rational(num, 1) {}\n    \n    bool is(int target) const {\n        if (denom == 0 ||
```c++\nclass Rational {\npublic:\n    Rational() {}\n    Rational(int num) : Rational(num, 1) {}\n    \n    bool is(int target) const {\n        if (denom == 0 || num % denom != 0)\n            return false;\n        return num / denom == target;\n    }\n\n    friend Rational operator+(const Rational &lhs, const Rational &rhs) {\n        return Rational{lhs.num * rhs.denom + lhs.denom * rhs.num, lhs.denom * rhs.denom};\n    }\n    friend Rational operator-(const Rational &lhs, const Rational &rhs) {\n        return Rational{lhs.num * rhs.denom - lhs.denom * rhs.num, lhs.denom * rhs.denom};\n    }\n    friend Rational operator*(const Rational &lhs, const Rational &rhs) {\n        return Rational{lhs.num * rhs.num, lhs.denom * rhs.denom};\n    }\n    friend Rational operator/(const Rational &lhs, const Rational &rhs) {\n        return Rational{lhs.num * rhs.denom, lhs.denom * rhs.num};\n    }\n\nprivate:\n    Rational(int num, int denom) : num(num), denom(denom) {}\n\n    int num;\n    int denom;\n};\n\n\nclass Solution {\npublic:\n    bool judgePoint24(vector<int>& nums) {\n        return judgePoint24<4>({nums[0], nums[1], nums[2], nums[3]});\n    }\n\n    bool judgePoint24(const array<Rational, 1>& nums) {\n        return nums[0].is(24);\n    }\n\n    template <size_t N>\n    bool judgePoint24(const array<Rational, N>& nums) {\n        for(int i = 0; i < nums.size(); ++i) {\n            for(int j = i + 1; j < nums.size(); ++j) {\n                if (judgePoint24(compute(nums, i, j,       plus<Rational>())) ||\n                    judgePoint24(compute(nums, i, j,      minus<Rational>())) ||\n                    judgePoint24(compute(nums, j, i,      minus<Rational>())) ||\n                    judgePoint24(compute(nums, i, j, multiplies<Rational>())) ||\n                    judgePoint24(compute(nums, i, j,    divides<Rational>())) ||\n                    judgePoint24(compute(nums, j, i,    divides<Rational>())))\n                    return true;\n            }\n        }\n        return false;\n    }\n\n    template <typename T, size_t N>\n    array<Rational, N-1> compute(const array<Rational, N> &nums, int i, int j, T op) {\n        array<Rational, N-1> result;\n        result[0] = op(nums[i], nums[j]);\n\n        int index = 1;\n        for (int k = 0; k < N; ++k)\n            if (k != i && k != j)\n                result[index++] = nums[k];\n\n        return result;\n    }\n};\n```
[]