I have found many solutions giving a collection elements combined in all possible orders but they all use every element just once in every result while I need them to be tr
You can use a depth first search:
class Program
{
private static string[] letters = {"a", "b", "c"};
private static void dfs(string accum, int depth)
{
if (depth == 0)
{
System.Console.WriteLine(accum);
return;
}
foreach (string c in letters)
dfs(accum + c, depth - 1);
}
public static void Main()
{
int depth = 2; //Number of letters in each result
dfs("", depth);
System.Console.ReadLine();
}
}
Output:
aa
ab
ac
ba
bb
bc
ca
cb
cc