1

Given buckets of unique numbers, how do we generate all combinations where you choosing a number from each bucket only once.

For example, if given {1,12,3} and {4,22,6} the answer is:
1/4 12/22 3/6
1/4 12/6 3/22
1/22 12/4 3/6
1/22 12/6 3/4
1/6 12/4 3/22
1/6 12/22 3/4

Of course, we don't just want 2 buckets, but n buckets. And each bucket can contain any amount of numbers; the numbers are unique across buckets.

Any algorithm in c# would be appreciated. I would expect the result to be something like: List<List<int[]>>

Thanks!

JPReddy
  • 63,233
  • 16
  • 64
  • 93
DuckoDeath
  • 11
  • 1
  • 3
  • 3
    Please post the code you have written so far. People generally do not like to just write your code for you. As it is, this is a work description, not a question. – Mitch Wheat Feb 27 '11 at 06:03
  • 6
    Smells like homework – Thomas Feb 27 '11 at 06:04
  • Have you tried anything so far? If you have tried something and still not getting, then give us info on what you have tried so that we can guide you further to get it done. – JPReddy Feb 27 '11 at 06:10
  • possible duplicate of [Generating all Possible Combinations](http://stackoverflow.com/questions/3093622/generating-all-possible-combinations) – Gabe Feb 27 '11 at 06:48
  • All the 'generating all possible combination' posts I have seen end up generating a cartesian product. This is not quite that problem. – DuckoDeath Feb 27 '11 at 16:53

1 Answers1

0

Take a look at this:

C# Permutation of an array of arraylists?

And this:

Fast permutation -> number -> permutation mapping algorithms

Community
  • 1
  • 1
Yochai Timmer
  • 48,127
  • 24
  • 147
  • 185