makeNullSafe static method
Returns a null safe copy of provided sudoku
to make it usable.
Replaces null
with 0
in the sudoku
.
InvalidSudokuConfigurationException is thrown if the configuration of
the sudoku
is not valid.
Implementation
static List<List<int>> makeNullSafe(List<List<int?>> sudoku) {
var nullSafeSudoku = List.generate(9, (i) => List.generate(9, (j) => 0));
try {
for (var i = 0; i < 9; i++) {
for (var j = 0; j < 9; j++) {
nullSafeSudoku[i][j] = sudoku[i][j] ?? 0;
}
}
} on RangeError {
throw InvalidSudokuConfigurationException();
}
if (!isValidConfiguration(nullSafeSudoku)) {
throw InvalidSudokuConfigurationException();
}
return nullSafeSudoku;
}