示例#1
0
        /// <summary>
        /// Uses the hash table created from the hint phrase to exclude single words.
        /// </summary>
        /// <param name="word"></param>
        /// <returns></returns>
        private bool IsSubPhraseValid(string word)
        {
            var invalid = true;

            // word must be shorter than or equal to the length of the hint phrase
            if (CheckLength(word))
            {
                var wordCharCountDictionary = GetCharCountFromString(word);

                foreach (var keyValuePair in wordCharCountDictionary)
                {
                    if (!CharCountFromHint.ContainsKey(keyValuePair.Key) || CharCountFromHint[keyValuePair.Key] < keyValuePair.Value)
                    {
                        // if the hash table does have the char or the number of times the char appears is to large the word will be excluded.
                        invalid = false;
                        break;
                    }
                }
            }
            else
            {
                // word is too long
                invalid = false;
            }

            return(invalid);
        }
示例#2
0
        /// <summary>
        /// Uses the hash table created from the hint phrase to exclude phrases.
        /// </summary>
        /// <param name="phrase"></param>
        /// <returns></returns>
        private bool IsPhraseAnagram(string phrase)
        {
            var isAnagram = true;

            // phrase must exactly match the length of the hint phrase
            if (phrase.Length == HintPhrase.Length)
            {
                var wordCharCount = GetCharCountFromString(phrase);

                foreach (var keyValuePair in wordCharCount)
                {
                    if (!CharCountFromHint.ContainsKey(keyValuePair.Key) || CharCountFromHint[keyValuePair.Key] != keyValuePair.Value)
                    {
                        // if the hash table does have the char or the number of times the char appears is to large the word will be excluded.
                        isAnagram = false;
                        break;
                    }
                }
            }
            else
            {
                isAnagram = false;
            }

            return(isAnagram);
        }
示例#3
0
        private void InitializeProperties()
        {
            ClearCollections();

            CharCountFromHint   = GetCharCountFromString(HintPhrase);
            NumWords            = (CharCountFromHint.ContainsKey(' ') ? CharCountFromHint[' '] : 0) + 1;
            SingleWordMaxLength = HintPhrase.Length - (NumWords - 1) - (CharCountFromHint.ContainsKey(' ') ? CharCountFromHint[' '] : 0);

            MakeDistinctWordList();
            CreateWordHash();
            GetMaxPhraseLengths();
            GetMinPhraseLengths();

            MD5Hash                  = MD5.Create();
            SecretPhrase             = null;
            SecretPhraseFound        = false;
            NumNodes                 = 0;
            NumMD5HashKeyComparisons = 0;
        }