From 8ca4a5e0a5b6984f54e74f5e348cb86a7176b15f Mon Sep 17 00:00:00 2001 From: Christoph Prybila Date: Wed, 4 Mar 2020 22:03:37 +0100 Subject: [PATCH] Adapted description and extended testdata --- README.md | 26 ++++++++++++++++++-------- src/test/resources/sudoku6.txt | 9 +++++++++ src/test/resources/sudoku7.txt | 9 +++++++++ src/test/resources/sudoku8.txt | 9 +++++++++ src/test/resources/testdata.csv | 3 +++ 5 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 src/test/resources/sudoku6.txt create mode 100644 src/test/resources/sudoku7.txt create mode 100644 src/test/resources/sudoku8.txt diff --git a/README.md b/README.md index 29d796a..6fbc7a7 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/test/resources/sudoku6.txt b/src/test/resources/sudoku6.txt new file mode 100644 index 0000000..5aa6860 --- /dev/null +++ b/src/test/resources/sudoku6.txt @@ -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 \ No newline at end of file diff --git a/src/test/resources/sudoku7.txt b/src/test/resources/sudoku7.txt new file mode 100644 index 0000000..42519d4 --- /dev/null +++ b/src/test/resources/sudoku7.txt @@ -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 \ No newline at end of file diff --git a/src/test/resources/sudoku8.txt b/src/test/resources/sudoku8.txt new file mode 100644 index 0000000..fed9899 --- /dev/null +++ b/src/test/resources/sudoku8.txt @@ -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 \ No newline at end of file diff --git a/src/test/resources/testdata.csv b/src/test/resources/testdata.csv index 788cdbd..2979be3 100644 --- a/src/test/resources/testdata.csv +++ b/src/test/resources/testdata.csv @@ -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 \ No newline at end of file