private bool IsValidSectionOfGrid(int[] grid, int index) { var positions = _positionCalculator.GetPosition(index); var row = _sectionCutter.GetSingleRow(grid, positions[0]); var column = _sectionCutter.GetSingleColumn(grid, positions[1]); var square = _sectionCutter.GetSingleSquare(grid, positions[0], positions[1]); return(!ContainsNoDuplicates(row) && !ContainsNoDuplicates(column) && !ContainsNoDuplicates(square)); }
private int[][] GetPossibleNumbersInGrid(int[] gridIntArray) { var possibilities = new int[81][]; int indexInGrid = 0; var rawRows = _sectionCutter.GetAllRows(gridIntArray); var allRows = rawRows.ToJaggedArray(); var allColumns = _sectionCutter.GetAllColumns(gridIntArray).ToJaggedArray(); var allSquares = _sectionCutter.GetAllSquares(gridIntArray).ToJaggedArray(); for (int i = 0; i < 81; i++) { var number = gridIntArray[i]; if (number == 0) { var possibleNumbers = Helper.ZeroToNineArray.AsEnumerable(); var position = _positionCalculator.GetPosition(indexInGrid); var currentRow = allRows[position[0]]; var currentColumn = allColumns[position[1]]; var currentSquare = allSquares[position[2]]; var itemsToRemove = currentRow.Union(currentColumn).Union(currentSquare); possibleNumbers = possibleNumbers.Except(itemsToRemove); possibilities[i] = possibleNumbers.ToArray(); } else { possibilities[i] = new int[1] { gridIntArray[indexInGrid] }; } ++indexInGrid; } return(possibilities); }