Пример #1
0
        // Method establishes which values can fill an empty square by eliminating any values already occurring in row/column/box.
        public List<int> DetermineValidOptionsForSquare(SquareCoordinate squareCoordinate, IImmutableSudokuGrid grid)
        {
            HashSet<int> validSquareOptions = new HashSet<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            for (int offset = 1; offset < 9; offset++)
            {
                validSquareOptions.Remove(grid.Elements[(squareCoordinate.Row + offset) % 9, squareCoordinate.Column]);
                validSquareOptions.Remove(grid.Elements[(squareCoordinate.Row), (squareCoordinate.Column + offset) % 9]);
                validSquareOptions.Remove(grid.Elements[(3 * (squareCoordinate.Row / 3)) + offset % 3, (3 * (squareCoordinate.Column / 3)) + (offset - offset % 3) / 3]);
            }

            return validSquareOptions.ToList<int>();
        }
Пример #2
0
        // Method establishes which values can fill an empty square by eliminating any values already occurring in row/column/box.
        public List <int> DetermineValidOptionsForSquare(SquareCoordinate squareCoordinate, IImmutableSudokuGrid grid)
        {
            HashSet <int> validSquareOptions = new HashSet <int> {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            };

            for (int offset = 1; offset < 9; offset++)
            {
                validSquareOptions.Remove(grid.Elements[(squareCoordinate.Row + offset) % 9, squareCoordinate.Column]);
                validSquareOptions.Remove(grid.Elements[(squareCoordinate.Row), (squareCoordinate.Column + offset) % 9]);
                validSquareOptions.Remove(grid.Elements[(3 * (squareCoordinate.Row / 3)) + offset % 3, (3 * (squareCoordinate.Column / 3)) + (offset - offset % 3) / 3]);
            }

            return(validSquareOptions.ToList <int>());
        }