Ok, here is the problem that I'm having at the moment: I have a list of elements with which I want to make pairs of all possible combinations.
For example: I have a list of elements "A", "B", "C", "E".
Out of those elements I want to make pairs of all possible combinations (without duplicate elements that already exist while pairing elements), so it would become:
AB
AC
AE
BC
BE
CE
ABC
ABE
ACE
BCE
ABCE
So far, my code doesn't make all combinations like in the example above and it seems to be having a problem with duplicates and I've ran out of ideas how to approach this any further.
List<char> charList = new List<char> { 'A', 'B', 'C', 'E' };
List<string> copy = new List<string>();
List<string> stringList = new List<string>();
for (int i = 0; i < charList.Count() - 1; i++)
{
for (int j = i + 1; j < charList.Count(); j++)
{
stringList.Add(charList[i].ToString() + charList[j].ToString());
copy = stringList.ToList();
}
}
for (int i = 0; i < charList.Count() - 1; i++)
{
for (int j = i + 1; j < charList.Count(); j++)
{
for (int g = 0; g < stringList.Count(); g++)
{
if (!stringList[g].Contains(charList[i]))
{
stringList[g] += charList[i];
copy.Add(stringList[g]);
}
else if (!stringList[g].Contains(charList[j]))
{
stringList[g] += charList[j];
copy.Add(stringList[g]);
}
}
}
}
foreach (string value in copy)
{
Console.WriteLine(value);
}
Thanks.