List all Permutations of a set of Questions and Answers

Viewed 30

I have a set of Questions, each question has a set of available answers I'm trying to get a list of all the possible permutations, using .NET Core

I have this list of Questions with the available answers,

Question1 Yes/No/Maybe

Question2 Yes/No

Question3 Yes/No

And need something like the below, which is all possible permutations of ALL questions, I have looked at a lot of permutation code, but all deals with a single list

Output would be something like this, (I think this is all the possible permutations of the above)

Yes Yes Yes

No No No

Yes Yes No

No No Yes

Yes No No

Yes Yes No

No Yes No

Yes No Yes

Maybe Yes No

Maybe No Yes

Maybe Yes Yes

Maybe No No 
1 Answers

Just use some thing like this:

var list1 = new List<string>() { "Yes", "No", "Maybe" };
            var list2 = new List<string>() { "Yes", "No" };
            var list3 = new List<string>() { "Yes", "No" };
            var paris = (from l1 in list1
                         from l2 in list2
                         from l3 in list3
                         select new { Pair = $"{l1}{l2}{l3}" }).ToList();
Related