Thomas Cook
Thomas Cook

Reputation: 4853

How to get all combinations of a set of sets?

I have a set of sets of strings.

I need to find every possible combination of strings.

Any ideas of the best way to go about this?

The language is C#, but I'm not looking for a concrete implementation, just a general approach to the problem.

Upvotes: 0

Views: 621

Answers (1)

kendzi
kendzi

Reputation: 331

Put string into Listn and then create method that will generate random combination of your elements. Something like in:

How to make a combination of strings in C#?

EDIT: Merge all Lists of string List into one long List of string.

    List<List<String>> sets = new List<List<String>>();
    List<String> allProducts = new List<String>();
    List<String> set1 = new List<String>() { "one", "two", "three" };
    List<String> set2 = new List<String>() { "111", "222", "333" };

    sets.Add(set1);
    sets.Add(set2);

    foreach (var set in sets)
    {
        allProducts.AddRange(set);
    }

Then perform operation on allProducts like in entry from above.

Upvotes: 1

Related Questions