Exemplo n.º 1
0
        private IEnumerable<string> InternalGetAnagrams(Dictionary<char, int> tiles, List<string> path, Node root,
                                                    int minLength, int minWordLength)
        {
            if (final && depth >= minWordLength)
              {
            var word = string.Join("", path);
            var length = word.Replace(" ", "").Length;
            if (length >= minLength)
              yield return word;

            using (new Guard(() => path.Push(" "), path.Pop))
            {
              foreach (var anagram in root.InternalGetAnagrams(tiles, path, root, minLength, minWordLength))
            yield return anagram;
            }
              }

              foreach (var child in children)
              {
            var l = child.Key;

            var count = tiles.Get(l);
            if (count == 0)
              continue;

            using (new Guard(() => tiles[l] = count - 1, () => tiles[l] = count))
            using (new Guard(() => path.Push(l.ToString()), path.Pop))
            {
              var node = child.Value;
              foreach (var anagram in node.InternalGetAnagrams(tiles, path, root, minLength, minWordLength))
            yield return anagram;
            }
              }
        }
Exemplo n.º 2
0
        private static Node LoadDictionary(string wordlist)
        {
            var result = new Node();

              wordlist
            .Split(new[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
            .Select(word => word.Trim().ToLowerInvariant())
            .ToList()
            .ForEach(result.Add);

              return result;
        }
Exemplo n.º 3
0
 private void MainForm_Load(object sender, EventArgs e)
 {
     dictionary = LoadDictionary(Resources.WordsList);
 }