Why doesn't this produce the correct number of string permutations? For
perm("ABC", 3)
it should print 27 different permutations.
private static List<string> permutated = new List<string>(30000);
public static List<string> perm(string s, int k) { return comb(s, "", k); }
private static List<string> perm(string s, string prefix, int k)
{
if (k == 0)
{
permutated.Add(prefix);
}
else
{
for (int i = 0; i < s.Length; i++)
{
perm( s.Substring( i + 1 ), prefix + s[i], k - 1 );
}
}
return permutated;
}