Advertisement
Guest User

Untitled

a guest
Apr 18th, 2015
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace PasswordTableTest
  6. {
  7. static class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. // Create a list of strings defining the charset for each index.
  12. var charsets = new List<string>
  13. { "abcdef", "defghi", "ghijkl", "jklmno", "mnopqrstuvwxyz", "pq234r", "st2342u" };
  14.  
  15. // Get the IEnumerable (note: This does not generate the permutations, just gives an IEnumerable to enumerate through thema ll)
  16. var cp = CartesianProduct(charsets);
  17.  
  18. // Print them out
  19. string row = "";
  20. foreach (string s in cp.Select(set => set.Aggregate("", (a, b) => a + b)))
  21. {
  22. row += s + ' ';
  23. if (row.Length > 60)
  24. {
  25. Console.WriteLine(row);
  26. row = "";
  27. }
  28. }
  29. Console.ReadKey();
  30. }
  31. public static IEnumerable<IEnumerable<T>> CartesianProduct<T>(this IEnumerable<IEnumerable<T>> sequences)
  32. {
  33. IEnumerable<IEnumerable<T>> result = new[] { Enumerable.Empty<T>() };
  34. return sequences.Aggregate(result, (current, s) =>
  35. (from seq in current from item in s select seq.Concat(new[] {item})));
  36. }
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement