I am trying to create a method that generates all possible combinations of letters within a limit set by the user. I have tried using a simple recursive nested foreach loop, I tried the same using parallel iterators, and this is my latest attempt which is linq with the parallel option set. So far this is probably the fastest method, but it still leaves something to be desired in terms of speed. I am just curious if anyone knows of any further methods to speed up this process?
This is the code at the moment, which is just the parallel linq inside of a worker, so the form can be updated of the progress.
It currently generates around: 11,881,376 combinations per minute
BackgroundWorker bw = new BackgroundWorker();
bw.DoWork += new DoWorkEventHandler(
delegate(object o, DoWorkEventArgs args) {
var total = 6; // how many characters to generate
var alphabet = "abcdefghijklmnopqrstuvwxyz";
var q = alphabet.Select(xf => x.ToString());
for (int i = 0; i < total - 1; i++) {
q = q.AsParallel().SelectMany(xf => alphabet, (xf, y) => xf + y);
//bw.ReportProgress(q.Count());
}
});
bw.RunWorkerAsync();