isSolved static method

bool isSolved(
  1. List<List<int>> sudoku
)

Returns true if the configuration of the sudoku is valid and there are no 0s/empty squares.

Recommended to use this to check if a game is solved instead of comparing with a solved sudoku. This is to prevent false-negatives when a puzzle has more than one solution.

InvalidSudokuConfigurationException is thrown if the configuration of the sudoku is not valid.

Implementation

static bool isSolved(List<List<int>> sudoku) {
  if (!isValidConfiguration(sudoku)) {
    throw InvalidSudokuConfigurationException();
  }
  for (var i = 0; i < 9; i++) {
    if (sudoku[i].contains(0)) {
      return false;
    }
  }
  return true;
}