mapToSudokuBoard

Converts a string representation of a Sudoku board to a two-dimensional list of integers.

This function converts a string representation of a Sudoku board to a two-dimensional list of integers. It uses the provided dimension to determine the size and structure of the board, and assumes that the string contains encoded cell values that can be decoded to integers.

Example:

val sudokuString: String = "ABCDDCBAABCDBADC"

// Convert the string to a 4x4 Sudoku board
val sudokuBoard: List<List<Int>> = sudokuString.mapToSudokuBoard(SudokuType.Sudoku4x4)

// The resulting sudokuBoard will be a 4x4 list of integers
// For Sudoku4x4, you would get:
// [
// [1, 2, 3, 4],
// [4, 3, 2, 1],
// [1, 2, 3, 4],
// [2, 1, 4, 3],
// ]

Receiver

The string representing the Sudoku board.

Return

A two-dimensional list of integers representing the Sudoku board, where each cell is converted to an integer using its default decoding.

Parameters

dimension

The type of Sudoku board (e.g., 4x4, 9x9), used to determine the size and structure of the board.

See also


inline fun <T> String.mapToSudokuBoard(dimension: Dimension, crossinline valueMapper: Int.() -> T): List<List<T>>

Converts a string representation of a Sudoku board to a two-dimensional list of elements of type T.

This function converts a string representing a Sudoku board to a two-dimensional list where each integer cell value is mapped to an element of type T using the provided valueMapper function. It uses the dimension to determine the size and structure of the board and assumes that the string contains encoded cell values that can be decoded to integers.

Example:

val sudokuString: String = "ABCDDCBAABCDBADC"

// Example with a custom valueMapper that maps integers to their string representation
val sudokuBoardString: List<List<String>> = sudokuString.mapToSudokuBoard(SudokuType.Sudoku4x4) { toString() }

// The resulting sudokuBoardString will be a 4x4 list of strings
// For Sudoku4x4, you would get:
// [
// ["1", "2", "3", "4"],
// ["4", "3", "2", "1"],
// ["1", "2", "3", "4"],
// ["2", "1", "4", "3"],
// ]

Receiver

The string representing the Sudoku board.

Return

A two-dimensional list of elements of type T representing the Sudoku board, where each cell is converted using the provided valueMapper function.

Parameters

dimension

The type of Sudoku board (e.g., 4x4, 9x9), used to determine the size and structure of the board.

valueMapper

A function that maps each integer value to an element of type T.

See also