I have been trying to permute items that I have in a simple list and I have used the below code from this question but it is very slow when the size of sequence gets very large.
static IEnumerable<IEnumerable<T>>
GetPermutations<T>(IEnumerable<T> list, int length)
{
if (length == 1) return list.Select(t => new T[] { t });
return GetPermutations(list, length - 1)
.SelectMany(t => list.Where(e => !t.Contains(e)),
(t1, t2) => t1.Concat(new T[] { t2 }));
}
For example when the length of output needs to be large, then this method takes a long time to be execute.
An example of the problem would be, we have 25 alphabets and we want to know all possible 5-charterer long words that can we generate with them.
Is there any other method that can run faster than this?