Advertisement
Guest User

TextTwist_golf_csharp

a guest
May 24th, 2012
98
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void FindWords(string letters)
  2. {
  3.     var dictionary = new HashSet<string>(File.ReadAllLines("e"));
  4.  
  5.     for (var i = 3; i < 8; i++)
  6.         foreach (var s in WordPermutations(letters, i).Where(dictionary.Contains).Distinct())
  7.             Console.WriteLine(s);
  8. }
  9.  
  10. IEnumerable<int[]> Permutations(int n, int r, int[] current = null)
  11. {
  12.     current = current ?? new int[] { };
  13.  
  14.     if (current.Length < r)
  15.         for (var i = 0; i < n; i++)
  16.             foreach (var i1 in Permutations(n, r, current.Concat(new[] { i }).ToArray()))
  17.                 yield return i1;
  18.     else
  19.         if (current.Length == current.Distinct().Count())
  20.             yield return current;
  21. }
  22.  
  23. IEnumerable<string> WordPermutations(string word, int taken)
  24. {
  25.     return Permutations(word.Length, taken)
  26.         .Select(p => new string(p.Select(i => word[i]).ToArray()));
  27. }
Advertisement
RAW Paste Data Copied
Advertisement