Dimension
Creates a Dimension instance based on the provided digit count.
This function is a convenience wrapper around Dimension.fromDigitCount. It simplifies the creation of a Dimension instance by directly using a digit count. If the digit count does not match any of the known Sudoku grid sizes, it will throw an InvalidDimensionException.
Example Usage:
// Example 1: Creating a Dimension for a 4x4 Sudoku grid
val dimension4x4 = Dimension(4)
println(dimension4x4) // Outputs: Dimension.FourByFour
// Example 2: Creating a Dimension for a 9x9 Sudoku grid
val dimension9x9 = Dimension(9)
println(dimension9x9) // Outputs: Dimension.NineByNine
// Example 3: Creating a Dimension for a 16x16 Sudoku grid
val dimension16x16 = Dimension(16)
println(dimension16x16) // Outputs: Dimension.SixteenBySixteen
// Example 4: Handling invalid digit count
try {
val invalidDimension = Dimension(7)
} catch (e: InvalidDimensionException) {
println(e.message) // Outputs: No dimension exists for digit count: 7
}
Content copied to clipboard
Parameters:
digitCount: Int
: The total number of unique digits (or cells) in a Sudoku grid. This number should be the square of the grid size (e.g., 9 for a 3x3 grid, 16 for a 4x4 grid, etc.).
Returns:
Throws:
InvalidDimensionException: If the provided
digitCount
does not correspond to any known Sudoku dimension.