fromDigitCount

fun fromDigitCount(digitCount: Int): Dimension

Returns the corresponding Dimension instance based on the provided digit count.

This function maps common Sudoku grid sizes, identified by their digit count, to their respective Dimension instances. If the provided digit count does not match any of the predefined Sudoku sizes, it throws an InvalidDimensionException.

Example Usage:

// Example 1: Retrieving the Dimension for a 4x4 Sudoku grid
val dimension4x4 = Dimension.fromDigitCount(4)
println(dimension4x4) // Outputs: Dimension.FourByFour

// Example 2: Retrieving the Dimension for a 9x9 Sudoku grid
val dimension9x9 = Dimension.fromDigitCount(9)
println(dimension9x9) // Outputs: Dimension.NineByNine

// Example 3: Retrieving the Dimension for a 16x16 Sudoku grid
val dimension16x16 = Dimension.fromDigitCount(16)
println(dimension16x16) // Outputs: Dimension.SixteenBySixteen

// Example 4: Handling invalid digit count
try {
val invalidDimension = Dimension.fromDigitCount(7)
} catch (e: InvalidDimensionException) {
println(e.message) // Outputs: No dimension exists for digit count: 7
}

Parameters:

  • digitCount: Int: The total number of unique digits (or cells) in a Sudoku grid. This is usually the square of the grid size (e.g., 9 for a 3x3 grid, 16 for a 4x4 grid, etc.).

Returns:

  • Dimension: The corresponding Dimension instance if the digitCount matches a known Sudoku grid size.

Throws: