Click here to Skip to main content
15,887,290 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 of 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.
...?
------------------------------------------------
Here is possible organization of input data:
C#
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 given sets from inputList with unique integers in each internal list (combination).
Posted
Updated 14-Dec-13 9:34am
v2
Comments
BillWoodruff 15-Dec-13 2:51am    
CodeProject resources on Permutations and Combinations in C#:

http://www.codeproject.com/search.aspx?q=permutations&x=-862&y=-163&sbo=kw
Sean Keller 13-Feb-23 16:48pm    
I know this thread is really old, but did you ever find a solution for this? I have the exact same question

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900