I have a set of characters: "ab", I need every combinations and permutations of it to given length. What I need sets like these if I give the length of 3: a, b, aa, ab, ba, bb, aaa, aab, aba, abb, baa, bab, bba, bbb
and so on.
I found a sort of good solution (https://stackoverflow.com/a/3640224/18535919), but I think it is a bit complicated. I have found a good solution in the past but I can not find it again.
static int maxlength = 3;
static string ValidChars = "abc";
static void Dive(string prefix, int level)
{
level += 1;
foreach (char c in ValidChars)
{
Console.WriteLine(prefix + c);
if (level < maxlength)
{
Dive(prefix + c, level);
}
}
}