# Compare the Triplets

See the original problem on HackerRank.

## Solutions

This is clearly an easy problem we can experiment with.

The easiest way to write the solution in C++ is:

  1 2 3 4 5 6 7 8 9 10 11 12 13 14  array a, b; copy_n(istream_iterator(cin), 3, begin(a)); copy_n(istream_iterator(cin), 3, begin(b)); int alice_points = 0; int bob_points = 0; for(int i = 0; i < 3; i++) { if (a[i] > b[i]) alice_points++; if (a[i] < b[i]) bob_points++; } 

We can use inner_product to exploit the zip | map | reduce pattern:

 1 2 3 4 5 6  array a, b; copy_n(istream_iterator(cin), 3, begin(a)); copy_n(istream_iterator(cin), 3, begin(b)); cout << inner_product(begin(a), end(a), begin(b), 0, plus(), greater()) << " " << inner_product(begin(b), end(b), begin(a), 0, plus(), greater()); }

A Java alternative:

 1 2 3  pointsAlice = ((a0>b0)?1:0) + ((a1>b1)?1:0) + ((a2>b2)?1:0); pointsBob = ((a0
We've worked on this challenge in these gyms: modena