public bool TryAndSolveOnce(SudokuGrid inputGrid) { while (inputGrid.FindAllEmptySquares().Count != 0) { bool hasASquareBeenFilled = false; foreach (var emptySquare in inputGrid.FindAllEmptySquares()) { List <int> validOptionsForSquare = DetermineValidOptionsForSquare(emptySquare, inputGrid); if (validOptionsForSquare.Count == 0) { return(false); } if (validOptionsForSquare.Count == 1) { inputGrid.FillInSquare(emptySquare, validOptionsForSquare[0]); hasASquareBeenFilled = true; } } if (!hasASquareBeenFilled) { return(true); } } return(true); }
public bool TryAndSolveOnce(SudokuGrid inputGrid) { while (inputGrid.FindAllEmptySquares().Count != 0) { bool hasASquareBeenFilled = false; foreach (var emptySquare in inputGrid.FindAllEmptySquares()) { List<int> validOptionsForSquare = DetermineValidOptionsForSquare(emptySquare, inputGrid); if (validOptionsForSquare.Count == 0) { return false; } if (validOptionsForSquare.Count == 1) { inputGrid.FillInSquare(emptySquare, validOptionsForSquare[0]); hasASquareBeenFilled = true; } } if (!hasASquareBeenFilled) { return true; } } return true; }