Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void FindWords(string letters)
- {
- var dictionary = new HashSet<string>(File.ReadAllLines("e"));
- for (var i = 3; i < 8; i++)
- foreach (var s in WordPermutations(letters, i).Where(dictionary.Contains).Distinct())
- Console.WriteLine(s);
- }
- IEnumerable<int[]> Permutations(int n, int r, int[] current = null)
- {
- current = current ?? new int[] { };
- if (current.Length < r)
- for (var i = 0; i < n; i++)
- foreach (var i1 in Permutations(n, r, current.Concat(new[] { i }).ToArray()))
- yield return i1;
- else
- if (current.Length == current.Distinct().Count())
- yield return current;
- }
- IEnumerable<string> WordPermutations(string word, int taken)
- {
- return Permutations(word.Length, taken)
- .Select(p => new string(p.Select(i => word[i]).ToArray()));
- }
Advertisement
RAW Paste Data
Copied
Advertisement