I am working on a project where by I need to find all possible permutations of an array.
I have this working, to a point
var geneticsArray = new[] { new[] { "M", "V" }, new[] { "M", "V" }};
var perms = from a in geneticsArray[0]
from b in geneticsArray[1]
select new { a, b };
This presents me with all the options:
- MM
- VM
- MV
- VV
Which is correct, but it isnt what I want to achieve, as for my intents and purposes VM and MV are one and the same.
How do I get the convert MV to VM?
This example is very simple and only contains 2 groupings, there are infinite groupings possible, which is something I will deal with later, but just want to make you aware so the reply wasnt simply reverse the result.
Any help with this would be great.
Further Edit
With the following code I can see a count of each permutation:
var permCounts = from perm in perms group perm by perm into b select new { b.Key, Count = b.Count() };
This will tell me each of the afore mentioned options occurs once, which is not quite right, as outline above MV and MV are, in this case, the same. I need the code to understand this.
This is what I am looking for, not how to make it able to deal with a unknown number of combinations.
Thanks
e,f,g,hand even if it did compile, it wouldn't work anyway, because you're going beyond the bounds of the array.