src/anagramsolver/services/LoopSetsHelper.cs
/// <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>
Main loop - loops combinations of each set
Main loop - loops combinations of each set
protected virtual int LoopWordCombinationsInCurrentSet(int numberOfJackpots, TCurrentSetOfXPos currentSetLength, ref ulong combinationCounter, ref ulong subsetCounter)
        {
            var noOfWordsInSet = currentSetLength.DictOfWordLengths.Count;
            string[] listOfWordPermutationsReplacementString = PermutationsCreator.CreateListOfWordPermutationsReplacementStrings(noOfWordsInSet);
            var listOflistOfPointersToWords = new int[noOfWordsInSet][];
            ulong currentSetCombinations = 1;
            for (int i = 0; i < noOfWordsInSet; i++)
            {
                int wordNumberInSet = i + 1;
                listOflistOfPointersToWords[i] = _wordlistCtrl.TableByWordLength[currentSetLength.DictOfWordLengths[(short)wordNumberInSet] - 1].ToArray();
                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];
            recurseCombinations(currentSentence, currentSentenceIndex, ref numberOfJackpots, currentSetLength, ref combinationCounter, ref subsetCounter, 
                listOfWordPermutationsReplacementString, listOflistOfPointersToWords);
            return numberOfJackpots;
        }
protected virtual int LoopWordCombinationsInCurrentSet ( int numberOfJackpots , TCurrentSetOfXPos currentSetLength , ref ulong combinationCounter , ref ulong subsetCounter ) { var noOfWordsInSet = currentSetLength . DictOfWordLengths . Count ; string [ ] listOfWordPermutationsReplacementString = PermutationsCreator . CreateListOfWordPermutationsReplacementStrings ( noOfWordsInSet ) ; var listOflistOfPointersToWords = new int [ noOfWordsInSet ] [ ] ; ulong currentSetCombinations = 1 ; for ( int i = 0 ; i < noOfWordsInSet ; i ++ ) { int wordNumberInSet = i + 1 ; listOflistOfPointersToWords [ i ] = _wordlistCtrl . TableByWordLength [ currentSetLength . DictOfWordLengths [ ( short ) wordNumberInSet ] - 1 ] . ToArray ( ) ; currentSetCombinations = currentSetCombinations * ( ulong ) ( listOflistOfPointersToWords [ i ] . Length ) ; } _consoleWriteLine ( " " + string . Format ( " " , combinationCounter ) + " " + string . Format ( " " , subsetCounter ) + " " + currentSetLength . ToString ( ) + " " + string . Format ( " " , currentSetCombinations ) + " " ) ; var currentSentenceIndex = - 1 ; var currentSentence = new int [ noOfWordsInSet ] ; recurseCombinations ( currentSentence , currentSentenceIndex , ref numberOfJackpots , currentSetLength , ref combinationCounter , ref subsetCounter , listOfWordPermutationsReplacementString , listOflistOfPointersToWords ) ; return numberOfJackpots ; }
Main loop - loops combinations of each set
Main loop - loops combinations of each set
// 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 // for each word in the set put each listOfPointersToWords in a list // and calculate number of combinations // 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
None
numberOfJackpots
int
a counter of found sentences
a counter of found sentences
currentSetLength
TCurrentSetOfXPos
e.g [2, 7, 9] - 3 list of words having length 2, 7 and 9 chars
e . g [ 2 7 9 ] - 3 list of words having length 2 7 and 9 chars
ulong
ref
combinationCounter
a counter of all combinations in all sets
a counter of all combinations in all sets
subsetCounter
a counter of all valid subsets (of the anagram) in all sets
a counter of all valid subsets ( of the anagram ) in all sets