I have some fixed sets of integers, with distict increasing values in each a set, for example:
{1, 2, 4}, {1, 3}, {2, 4}, {2, 7}, {3, 6}, {5, 6}, {3, 5, 7}.
Is there any algorithm or better C# code, generating all possible combinations from given sets but without repetition of their internal integers, i.e.
[{1, 2, 4}, {3, 6}] < all integers are unique
[{1, 2, 4}, {3, 5, 7}] < all integers are unique
[{1, 3}, {2, 4}, {5, 6}] <– all integers are unique.
and so on.
====================================
Here is possible organization of input data:
var set1 = new HashSet<int>() { 1, 2, 4 };
var set2 = new HashSet<int>() { 1, 3 };
var set3 = new HashSet<int>() { 2, 4 };
var set4 = new HashSet<int>() { 2, 7 };
var set5 = new HashSet<int>() { 3, 6 };
var set6 = new HashSet<int>() { 5, 6 };
var set7 = new HashSet<int>() { 3, 5, 7 };
var inputList = new List<HashSet<int>>();
inputList.Add(set1);
inputList.Add(set2);
inputList.Add(set3);
inputList.Add(set4);
inputList.Add(set5);
inputList.Add(set6);
inputList.Add(set7);
I need to obtain a list (or collection) of all possible lists (i.e. combinations) of sets from inputList with unique integers in each internal list (combination).
This question was marked as duplicate and as a question which already has an answer here: “Generating all Possible Combinations (8 answers)”. However, to my mind, it is essentially a DIFFERENT question:
input data are not two arrays of the same length but rather a list of sets with different number of elements in each a set;
equal elements may be present in different sets.