[Solved] Print non repeating combinations [closed]


Interesting task. Try following code:

List<string> list = Enumerable.Range(1, 6).Select(e => ((char)('A' + e - 1)).ToString()).ToList();
List<string> temp = new List<string>();

int count = list.Count;
int total = 1 << list.Count;
for (int i = 0; i < total; i++)
{
    int k = i;
    temp.Clear();
    for (int j = 0; j < count; j++)
    {
        if ((k & 1) == 1)
        {
            temp.Add(list[j]);
        }
        k >>= 1;
    }
    Console.WriteLine(string.Join(" + ", temp.ToArray()));
}

Output:

A
B
A + B
C
A + C
B + C
A + B + C
D
A + D
B + D
A + B + D
C + D
A + C + D
B + C + D
A + B + C + D
E
A + E
B + E
A + B + E
C + E
A + C + E
B + C + E
A + B + C + E
D + E
A + D + E
B + D + E
A + B + D + E
C + D + E
A + C + D + E
B + C + D + E
A + B + C + D + E
F
A + F
B + F
A + B + F
C + F
A + C + F
B + C + F
A + B + C + F
D + F
A + D + F
B + D + F
A + B + D + F
C + D + F
A + C + D + F
B + C + D + F
A + B + C + D + F
E + F
A + E + F
B + E + F
A + B + E + F
C + E + F
A + C + E + F
B + C + E + F
A + B + C + E + F
D + E + F
A + D + E + F
B + D + E + F
A + B + D + E + F
C + D + E + F
A + C + D + E + F
B + C + D + E + F
A + B + C + D + E + F

solved Print non repeating combinations [closed]