gridToStrings method

List<String> gridToStrings({
  1. String onChar = '#',
  2. String offChar = '.',
})

Converts the matrix to a list of strings.

This method creates a list where each string represents a row in the matrix.

Parameters:

  • onChar: The character to represent true cells. Default is '#'.
  • offChar: The character to represent false cells. Default is '.'.

Returns: A List

Example:

// ["#.#", ".#.", "#.#"]

Implementation

List<String> gridToStrings({
  final String onChar = '#',
  final String offChar = '.',
}) {
  final List<String> result = [];

  for (int row = 0; row < rows; row++) {
    String rowString = '';
    for (int col = 0; col < cols; col++) {
      rowString += cellGet(col, row) ? onChar : offChar;
    }

    result.add(rowString);
  }

  return result;
}