1

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?

1 Answer 1

2

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})); 
}
Sign up to request clarification or add additional context in comments.

1 Comment

Beautiful. I always wondered how you'd do that in the general case. +1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.