Ejemplo n.º 1
0
        public static WordAndLetters RemoveMatchingLetters(WordAndLetters wordAndLetters)
        {
            if (!wordAndLetters.DictionaryWord.Any() || !wordAndLetters.Letters.Any())
            {
                return(wordAndLetters);
            }

            if (wordAndLetters.Letters.First() < wordAndLetters.DictionaryWord.First())
            {
                return(RemoveMatchingLetters(
                           new WordAndLetters(
                               wordAndLetters.DictionaryWord,
                               wordAndLetters.Letters.Skip(1)
                               )
                           ));
            }

            if (wordAndLetters.Letters.First() == wordAndLetters.DictionaryWord.First())
            {
                return(RemoveMatchingLetters(
                           new WordAndLetters(
                               wordAndLetters.DictionaryWord.Skip(1),
                               wordAndLetters.Letters.Skip(1)
                               )
                           ));
            }
            else
            {
                return(wordAndLetters);
            }
        }
Ejemplo n.º 2
0
        public static bool CanBeMadeFrom2(this string dictionaryWord, string letters)
        {
            var wordAndLetters = new WordAndLetters(
                dictionaryWord.Select(l => l).OrderBy(l => l),
                letters.Select(l => l).OrderBy(l => l)
                );

            return(RemoveMatchingLetters(wordAndLetters).IsWordEmpty());
        }