As part of an algorithm, I was meant to generate the whole set of all k − combinations efficiently. This may seem a really simple task but it is actually a little bit tricky, specially if one wants to handle large n/k values. The are out-of-the-box solutions which “do the job” but actually don’t work at all for not so big numbers.
Naive solutions can be implemented at once. For instance, the following would compute all comb(20, 5) combinations (please, consider to grab a coffee…) :
replicateM 5 [1..20]