Compare the Triplets

  • + 2 comments

    I have created what might be the worst possible functional solution:

    int compare(int a, int b)
    {
        if (a > b)
        {
            return 1;
        }
        else if (b > a)
        {
            return -1;
        }
        else
        {
            return 0;
        }
    }
    
    vector < int > solve(int a0, int a1, int a2, int b0, int b1, int b2){
        int a = 0; // Difference of A and B's scores
        int b = 0; // Number of points awarded in total
        int c = 0; // Current return value
        int d = 0; // This is A's score
        int e = 0; // This is B's score
        c = compare(a0,b0);
        a += c;
        b += abs(c);
        c = compare(a1,b1);
        a += c;
        b += abs(c);
        c = compare(a2,b2);
        a += c;
        b += abs(c);
        d = a + (b-a)/2;
        e = b - d;
        vector < int > retvals = {d, e};
        return retvals;
    }
    

    Good intentions lead me to bad code