Is there any way to convert the following code snippet to use for loops instead of the heavy LINQ usage?
public static IEnumerable<IEnumerable<T>> Combinations<T>(this IEnumerable<T> elements, int k)
{
return k == 0
? new[] {new T[0]}
: elements.SelectMany((e, i) =>
elements.Skip(i + 1).Combinations(k - 1).Select(c => (new[] {e}).Concat(c)));
}
The goal is to come up with all possible combinations of size k of a given list of elements.