fork download
  1. using System;
  2.  
  3. using System.Collections.Generic;
  4.  
  5. using System.Linq;
  6.  
  7. using System.Text;
  8.  
  9.  
  10.  
  11. namespace ConsoleApplication1
  12.  
  13. {
  14.  
  15. class Program
  16.  
  17. {
  18.  
  19. static void Main(string[] args)
  20.  
  21. {
  22.  
  23. string metachars = "abcde";
  24.  
  25. for (int i = 1; i <= metachars.Length; i++)
  26.  
  27. {
  28.  
  29. foreach (string s in foo(metachars, i))
  30.  
  31. {
  32.  
  33. Console.WriteLine(s);
  34.  
  35. }
  36.  
  37. }
  38.  
  39. }
  40.  
  41.  
  42.  
  43. static IEnumerable<string> foo(string metachars, int i)
  44.  
  45. {
  46.  
  47. var query = metachars.Select(x => x.ToString().AsEnumerable());
  48.  
  49. while (query.First().Count() < i)
  50.  
  51. query = query.SelectMany(x => metachars.Where(y => y > x.Last()).Select(y => x.Concat(y.ToString().AsEnumerable())));
  52.  
  53. return query.Select(x => string.Join(",", x));
  54.  
  55. }
  56.  
  57. }
  58.  
  59. }
Success #stdin #stdout 0.05s 24048KB
stdin
Standard input is empty
stdout
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