예제 #1
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);
        }
예제 #2
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);
        }
예제 #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;
        }
예제 #4
0
        private void ClearCollections()
        {
            if (DistinctWordList != null)
            {
                DistinctWordList.Clear();
                DistinctWordList = null;
            }

            if (CharCountFromHint != null)
            {
                CharCountFromHint.Clear();
                CharCountFromHint = null;
            }

            if (WordHash != null)
            {
                WordHash.Clear();
                WordHash = null;
            }

            MaxPhraseLengths = null;
            MinPhraseLengths = null;
        }