to2D static method

List<List<int>> to2D(
  1. List<int> sudoku
)

Returns a copy of the provided sudoku as a 2 Dimensional List which is the standard format.

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

Implementation

static List<List<int>> to2D(List<int> sudoku) {
  var sudoku2D = List.generate(9, (i) => List.generate(9, (j) => 0));
  var index = 0;
  try {
    for (var i = 0; i < 9; i++) {
      for (var j = 0; j < 9; j++) {
        sudoku2D[i][j] = sudoku[index];
        index++;
      }
    }
  } on RangeError {
    throw InvalidSudokuConfigurationException();
  }
  if (!isValidConfiguration(sudoku2D)) {
    throw InvalidSudokuConfigurationException();
  }
  return sudoku2D;
}