views:

86

answers:

1

I have 2 collections of caracter string ex:

List<string> one = new List<string>;
one.Add("a");
one.Add("b");
one.Add("c");

List<string> two = new List<string>;
two.Add("x");
two.Add("y");
two.Add("z");

What i would like to do is create a list of all the variations of words that can be created from this. But i only want to create 4 character words! so for example i would want words like

axax (from one[1],two[1],one[1],two[1])
ayax (from one[1],two[2],one[1],two[1])
azax (from one[1],two[3],one[1],two[1])

eventually getting to

czcz (from one[3],two[3],one[3],two[3])

Any suggestions on the fastest and best way to generate this

+3  A: 

I doubt this solution will win any speed awards, but it should be reasonably quick:

var one = new [] { "a", "b", "c" };
var two = new [] { "x", "y", "z" };

var ot = from o in one from t in two select o + t;
var r = from f in ot from s in ot select f + s;
var list = r.ToList();
Daniel Pratt