Example #1
0
        /// <summary>
        /// Main loop - loops combinations of each set
        /// </summary>
        /// <param name="numberOfJackpots">a counter of found sentences</param>
        /// <param name="currentSetLength">e.g [2, 7, 9] - 3 list of words having length 2, 7 and 9 chars</param>
        /// <param name="combinationCounter">a counter of all combinations in all sets</param>
        /// <param name="subsetCounter">a counter of all valid subsets (of the anagram) in all sets</param>
        /// <returns>numberOfJackpots</returns>
        protected virtual int LoopWordCombinationsInCurrentSet(int numberOfJackpots, TCurrentSetOfXPos currentSetLength, ref ulong combinationCounter, ref ulong subsetCounter)
        {
            var noOfWordsInSet = currentSetLength.DictOfWordLengths.Count;

            // Create list with permutations for string.Format: "{0} {1}" from [0,1] to [1,0] = 2 permutations
            // Create list with permutations for string.Format: "{0} {1} {2}" from [0,1,2] to [2,1,0] = 6 permutations
            // Create list with permutations for string.Format: "{0} {1} {2} {3}" from [0,1,2,3] to [3,2,1,0] = 24 permutations
            // Create list with permutations for string.Format: "{0} {1} {2} {3} {4}" from [0,1,2,3,4] to [4,3,2,1,0] = 120 permutations
            string[] listOfWordPermutationsReplacementString = PermutationsCreator.CreateListOfWordPermutationsReplacementStrings(noOfWordsInSet);

            var   listOflistOfPointersToWords = new int[noOfWordsInSet][];
            ulong currentSetCombinations      = 1;

            for (int i = 0; i < noOfWordsInSet; i++)
            {
                // for each word in the set put each listOfPointersToWords in a list
                int wordNumberInSet = i + 1;
                listOflistOfPointersToWords[i] = _wordlistCtrl.TableByWordLength[currentSetLength.DictOfWordLengths[(short)wordNumberInSet] - 1].ToArray();
                // and calculate number of combinations
                currentSetCombinations = currentSetCombinations * (ulong)(listOflistOfPointersToWords[i].Length);
            }

            _consoleWriteLine(" Combinations: " + string.Format("{0:n0}", combinationCounter) + ". Subsets: " + string.Format("{0:n0}", subsetCounter) + ". NextSet: " + currentSetLength.ToString() + " having " + string.Format("{0:n0}", currentSetCombinations) + " combinations");

            var currentSentenceIndex = -1;
            var currentSentence      = new int[noOfWordsInSet];

            // Since we know that there won't be any long words before len = 11, then we make the outer loop pass those 0 values first
            recurseCombinations(currentSentence, currentSentenceIndex, ref numberOfJackpots, currentSetLength, ref combinationCounter, ref subsetCounter,
                                listOfWordPermutationsReplacementString, listOflistOfPointersToWords);

            return(numberOfJackpots);
        }
        /// <summary>
        /// Create list with permutations for string.Format: "{0} {1} {2}"
        /// </summary>
        /// <param name="numberOfWordsInSentence">Number of words that should be replaced in string.Format</param>
        /// <returns>A list with a line foreach permutation</returns>
        public static string[] CreateListOfWordPermutationsReplacementStrings(int numberOfWordsInSentence)
        {
            int[] permutationValues = new int[numberOfWordsInSentence];
            for (int i = 0; i < numberOfWordsInSentence; i++)
            {
                permutationValues[i] = i;
            }

            // List from [0,1,2] to [2,1,0] = 6 permutations - used for swapping order of words in sentence
            //int[] permutationValues = new int[] { 0, 1, 2 };
            var listOfWordPermutations = PermutationsCreator.GetPermutations(permutationValues, permutationValues.Length);
            // Convert to a list for string.Format: "{0} {1} {2}"
            var listOfWordPermutationsReplacementStrings = PermutationsCreator.ToReplacementString(listOfWordPermutations).ToArray();;

            return(listOfWordPermutationsReplacementStrings);
        }