I recently solved a task on Stackoverflow. Please see here
Out of an array with 9 values, triplets consisting of 3 distinct values shall be generated. Calculating them is simple. Result is n choose k, 9 choose 3 = 84 triplets.
Next I needed to select 3 triplets, a triplet set, out of this set of 84 triplets where all values in the triplet set are also distinct. No double value anywhere.
Overall sets of triplets could again be calculated by n choose k, 84 choose 3 triplets = 95284 triplet sets. But, with the condition that all values in the triplet set should be distinct.
As a result I got 280 triplet groups (Via brute force).
Now, I do not know, if this number 280 is correct.
- How can this value be calculated?
- And how can the groups be calculated without brute force?
After you choose $3$ from the $9$, choose another $3$ from the remaining $6$. This splits all of the numbers into the three groups you want.
However, we have also overcounted. We have counted every permutation of $3$ triplets, so we need to divide by $3!$ to only get the combination of triplets.
$$ \frac{1}{3!}\binom{9}{3}\binom{6}{3} = 280 $$