コード例 #1
0
        private List <byte> EliminationSearch(IEnumerable <byte> rowColCellSearchSolutions)
        {
            var eliminationSearchSolutions = new List <byte>();

            foreach (var recentlyFoundIndex in rowColCellSearchSolutions)
            {
                var eliminatedElements = new List <byte>();

                // store digit for later
                var digit = Sudoku[recentlyFoundIndex];

                // Remove all line, col and cell entries (cannot go there again)
                foreach (var removerIndex in
                         SudokuSolver.GetRowIterator(recentlyFoundIndex)
                         .Union(SudokuSolver.GetColIterator(recentlyFoundIndex))
                         .Union(SudokuSolver.GetCellIterator(recentlyFoundIndex))
                         )
                {
                    var possibleSolutions = PossibilitySpace[removerIndex];

                    // Check if already set
                    if (possibleSolutions is null)
                    {
                        continue;
                    }

                    // Remove possibility
                    possibleSolutions.Remove(digit);

                    // check if only solution
                    if (possibleSolutions.Count == 1)
                    {
                        ProcessNewMatch(possibleSolutions.First(), (byte)removerIndex, ref eliminatedElements);
                    }
                }

                eliminationSearchSolutions.AddRange(eliminatedElements);
            }

            return(eliminationSearchSolutions);
        }