Please help, now I have a matrix, I want use Combination algorithm to generate a array for length 6

Posted by user313429 on Stack Overflow See other posts from Stack Overflow or by user313429
Published on 2010-04-10T11:13:51Z Indexed on 2010/04/10 11:23 UTC
Read the original article Hit count: 252

Filed under:

The first thanks a lot for your help , the following is my matrix, I want to implement combination algorithm between multiple arrays in LINQ for this matrix.

int[,] cj = { 
                        { 10, 23, 16, 20 },
                        { 22, 13, 1, 33 },
                        { 7, 19, 31, 12 },
                        { 30, 14, 21, 4 },
                        { 2, 29, 32, 6 },
                        { 18, 26, 17, 8 },
                        { 25, 11, 5, 28 },
                        { 24, 3, 15, 27 }
                    };

other:

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 above method has a error in my project, System.Collections.Generic.IEnumerable' does not contain a definition for 'Combinations' and no extension method 'Combinations' accepting a first argument of type 'System.Collections.Generic.IEnumerable' could be found (are you missing a using directive or an assembly reference?

I use .Net Framework3.5, what is the reason it?

© Stack Overflow or respective owner

Related posts about c#