I was looking for a way to get all unique permutations of a List by groups of 3. I found a lot of source code to download and complex algorithms.
I finally just came up with my own code that seems to work. Could someone please tell me why the following is not a good idea. I'm assuming there must be something I am overlooking due to all the complex solutions I found and mine seems too simple.
var combinations = from a in Samples
from b in Samples
from c in Samples
where (string)a.sample != (string)b.sample
&& (string)a.sample != (string)c.sample
&& (string)b.sample != (string)c.sample
select new Rank
{
sample = a.sample,
sampleb = b.sample,
samplec = c.sample
};
foreach (var combo in combinations)
{
string[] aut = { combo.sample, combo.sampleb, combo.samplec };
Array.Sort(aut);
combo.sample = aut[0];
combo.sampleb = aut[1];
combo.samplec = aut[2];
l.Add(combo);
}
noDupes = from n in l
group n by new { n.sample, n.sampleb, n.samplec } into g
select new Rank
{
sample = g.Key.sample,
sampleb = g.Key.sampleb,
samplec = g.Key.samplec
};