|
|
@ -1,21 +1,31 @@
|
|
|
|
# Sudoku verifier
|
|
|
|
# Validate a Sudoku
|
|
|
|
|
|
|
|
|
|
|
|
## Definition
|
|
|
|
## Definition
|
|
|
|
Sudokus are logic number puzzles in which cells in a 9×9 grid must be populated with
|
|
|
|
Sudokus are number-puzzles in which cells in a 9×9 grid must be populated with the numbers `1` to `9`.
|
|
|
|
the digits 1 to 9 in a way that each digit occurrs only once in each unit (that is column,
|
|
|
|
|
|
|
|
row or block = 3×3 sub grid).
|
|
|
|
The following constraints must apply to the 9×9 grid.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* Each digit from `1` to `9` only occurs only once
|
|
|
|
|
|
|
|
* per row
|
|
|
|
|
|
|
|
* per column
|
|
|
|
|
|
|
|
* per block (i.e. 3×3 sub grid)
|
|
|
|
|
|
|
|
|
|
|
|
![a solved simple sudoku](sudoku.gif)
|
|
|
|
![a solved simple sudoku](sudoku.gif)
|
|
|
|
|
|
|
|
|
|
|
|
## Goal
|
|
|
|
## Goal
|
|
|
|
Validate if a given solution for a Sudoku is valid, by checking that the digit
|
|
|
|
Validate, if a given Sudoku is a valid solution.
|
|
|
|
1 to 9 appear only once in column, in each row and in each of the 9 sub grids.
|
|
|
|
|
|
|
|
|
|
|
|
The Sudoku must comply with the definition above.
|
|
|
|
|
|
|
|
|
|
|
|
### Input
|
|
|
|
### Input
|
|
|
|
a sequence of 81 digits, organized in 9 columns and 9 rows
|
|
|
|
A sequence of 81 digits, organized in 9 columns and 9 rows.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The columns of a row are separated by blanks.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Rows are separated by line-breaks.
|
|
|
|
|
|
|
|
|
|
|
|
### Output
|
|
|
|
### Output
|
|
|
|
A boolean value, if the grid is valid.
|
|
|
|
A boolean value `true` or `false` defining the correctness of the input.
|
|
|
|
|
|
|
|
|
|
|
|
### Constraints
|
|
|
|
### Constraints
|
|
|
|
1 <= `digit` <= 9
|
|
|
|
1 <= `digit` <= 9
|
|
|
|