using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string metachars = "abcde"; for (int i = 1; i <= metachars.Length; i++) { foreach (string s in foo(metachars, i)) { Console.WriteLine(s); } } } static IEnumerable<string> foo(string metachars, int i) { var query = metachars.Select(x => x.ToString().AsEnumerable()); while (query.First().Count() < i) query = query.SelectMany(x => metachars.Where(y => y > x.Last()).Select(y => x.Concat(y.ToString().AsEnumerable()))); return query.Select(x => string.Join(",", x)); } } }
Standard input is empty
a b c d e a,b a,c a,d a,e b,c b,d b,e c,d c,e d,e a,b,c a,b,d a,b,e a,c,d a,c,e a,d,e b,c,d b,c,e b,d,e c,d,e a,b,c,d a,b,c,e a,b,d,e a,c,d,e b,c,d,e a,b,c,d,e