0
0
Fork 0

Adapted description and extended testdata

paul
Christoph Prybila 5 years ago
parent f5aa725b72
commit 8ca4a5e0a5

@ -1,21 +1,31 @@
# Sudoku verifier
# Validate a Sudoku
## Definition
Sudokus are logic number puzzles in which cells in a 9×9 grid must be populated with
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).
Sudokus are number-puzzles in which cells in a 9×9 grid must be populated with the numbers `1` to `9`.
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)
## Goal
Validate if a given solution for a Sudoku is valid, by checking that the digit
1 to 9 appear only once in column, in each row and in each of the 9 sub grids.
Validate, if a given Sudoku is a valid solution.
The Sudoku must comply with the definition above.
### 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
A boolean value, if the grid is valid.
A boolean value `true` or `false` defining the correctness of the input.
### Constraints
1 <= `digit` <= 9

@ -0,0 +1,9 @@
1 7 2 5 4 9 6 8 3
6 4 5 8 7 3 2 1 9
3 8 9 2 6 1 7 4 5
4 9 6 3 2 7 8 5 1
8 1 3 4 5 6 9 7 2
2 5 7 1 9 8 4 3 6
9 6 4 7 1 5 3 2 8
7 3 1 6 8 2 5 9 4
5 2 8 9 3 4 1 6 7

@ -0,0 +1,9 @@
9 5 7 6 1 3 2 8 4
4 8 3 2 5 7 1 9 6
6 1 2 8 4 9 5 3 7
1 7 8 3 6 4 9 5 2
5 2 4 9 7 1 3 6 8
3 6 9 5 2 8 7 4 1
8 4 5 7 9 2 6 1 3
2 9 1 4 3 6 8 7 5
7 3 6 1 8 5 4 2 9

@ -0,0 +1,9 @@
1 7 2 5 4 9 6 8 3
6 4 5 8 7 3 2 1 9
3 8 9 2 6 1 7 4 5
4 9 6 3 2 7 8 5 1
8 1 3 4 5 6 9 7 2
2 5 7 1 9 8 4 3 6
9 6 4 7 2 5 3 2 8
7 3 1 6 8 2 5 9 4
5 2 8 9 3 4 1 6 7

@ -3,3 +3,6 @@ sudoku2.txt, true
sudoku3.txt, false
sudoku4.txt, true
sudoku5.txt, false
sudoku6.txt, true
sudoku7.txt, true
sudoku8.txt, false
1 sudoku1.txt true
3 sudoku3.txt false
4 sudoku4.txt true
5 sudoku5.txt false
6 sudoku6.txt true
7 sudoku7.txt true
8 sudoku8.txt false
Loading…
Cancel
Save