user1237226
user1237226

Reputation:

C# List All Permutation

I have a problem.I developed a program with Apriori Algorithm.In Apriori Algorithm,I must take permutation values.For This

foreach (String s1 in array1) {

foreach (String s2 in array2) {

        String result = s1 + " " + s2 + " " + s3;
        //Processing

}
}

I coding something.But this code only taking binary permutation.I must take binary,triple,four,quintet permutations with Automatically. Do u have idea for this?

Upvotes: 1

Views: 401

Answers (1)

Servy
Servy

Reputation: 203829

Link

Code copied verbatim from the above link.

static IEnumerable<IEnumerable<T>> CartesianProduct<T>(this IEnumerable<IEnumerable<T>> sequences) 
{ 
  IEnumerable<IEnumerable<T>> emptyProduct = new[] { Enumerable.Empty<T>() }; 
  return sequences.Aggregate( 
    emptyProduct, 
    (accumulator, sequence) => 
      from accseq in accumulator 
      from item in sequence 
      select accseq.Concat(new[] {item})); 
}

Upvotes: 2

Related Questions