diff --git a/challenges/sudoku/README.md b/challenges/sudoku/README.md new file mode 100644 index 0000000..8875f36 --- /dev/null +++ b/challenges/sudoku/README.md @@ -0,0 +1,57 @@ +# sudoku + +Created by [@Divlo](https://github.com/Divlo) on 6 July 2021. + +## Instructions + +Sudoku is a logic-based, combinatorial number-placement puzzle. + +The objective is to fill a 9×9 grid with digits so that each column, each row, and each of the nine 3×3 subgrids that compose the grid (also called "boxes", "blocks", or "regions") contains all of the digits from 1 to 9. The puzzle setter provides a partially completed grid, which for a well-posed puzzle has a single solution. + +You can't use the same numbers twice in a : + +- row +- column +- square of 3x3 + +Write a program that solves the Sudoku given in input. + +The empty cells are represented by 0. + +## Source + +- [Wikipedia - Sudoku](https://en.wikipedia.org/wiki/Sudoku) + +## Examples + +See the `test` folder for examples of input/output. + +### Example 1 + +#### Input + +```txt +5 3 0 0 7 0 0 0 0 +6 0 0 1 9 5 0 0 0 +0 9 8 0 0 0 0 6 0 +8 0 0 0 6 0 0 0 3 +4 0 0 8 0 3 0 0 1 +7 0 0 0 2 0 0 0 6 +0 6 0 0 0 0 2 8 0 +0 0 0 4 1 9 0 0 5 +0 0 0 0 8 0 0 7 9 +``` + +#### Output + +```txt +5 3 4 6 7 8 9 1 2 +6 7 2 1 9 5 3 4 8 +1 9 8 3 4 2 5 6 7 +8 5 9 7 6 1 4 2 3 +4 2 6 8 5 3 7 9 1 +7 1 3 9 2 4 8 5 6 +9 6 1 5 3 7 2 8 4 +2 8 7 4 1 9 6 3 5 +3 4 5 2 8 6 1 7 9 +``` diff --git a/challenges/sudoku/solutions/.gitkeep b/challenges/sudoku/solutions/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/challenges/sudoku/test/1/input.txt b/challenges/sudoku/test/1/input.txt new file mode 100644 index 0000000..76acaed --- /dev/null +++ b/challenges/sudoku/test/1/input.txt @@ -0,0 +1,9 @@ +5 3 0 0 7 0 0 0 0 +6 0 0 1 9 5 0 0 0 +0 9 8 0 0 0 0 6 0 +8 0 0 0 6 0 0 0 3 +4 0 0 8 0 3 0 0 1 +7 0 0 0 2 0 0 0 6 +0 6 0 0 0 0 2 8 0 +0 0 0 4 1 9 0 0 5 +0 0 0 0 8 0 0 7 9 \ No newline at end of file diff --git a/challenges/sudoku/test/1/output.txt b/challenges/sudoku/test/1/output.txt new file mode 100644 index 0000000..f10ad45 --- /dev/null +++ b/challenges/sudoku/test/1/output.txt @@ -0,0 +1,9 @@ +5 3 4 6 7 8 9 1 2 +6 7 2 1 9 5 3 4 8 +1 9 8 3 4 2 5 6 7 +8 5 9 7 6 1 4 2 3 +4 2 6 8 5 3 7 9 1 +7 1 3 9 2 4 8 5 6 +9 6 1 5 3 7 2 8 4 +2 8 7 4 1 9 6 3 5 +3 4 5 2 8 6 1 7 9 \ No newline at end of file diff --git a/challenges/sudoku/test/2/input.txt b/challenges/sudoku/test/2/input.txt new file mode 100644 index 0000000..250ce63 --- /dev/null +++ b/challenges/sudoku/test/2/input.txt @@ -0,0 +1,9 @@ +0 1 0 0 4 0 0 5 0 +4 0 7 0 0 0 6 0 2 +8 2 0 6 0 0 0 7 4 +0 0 0 0 1 0 5 0 0 +5 0 0 0 0 0 0 0 3 +0 0 4 0 5 0 0 0 0 +9 6 0 0 0 3 0 4 5 +3 0 5 0 0 0 8 0 1 +0 7 0 0 2 0 0 3 0 \ No newline at end of file diff --git a/challenges/sudoku/test/2/output.txt b/challenges/sudoku/test/2/output.txt new file mode 100644 index 0000000..14d392c --- /dev/null +++ b/challenges/sudoku/test/2/output.txt @@ -0,0 +1,9 @@ +6 1 9 7 4 2 3 5 8 +4 5 7 8 3 1 6 9 2 +8 2 3 6 9 5 1 7 4 +2 3 6 4 1 9 5 8 7 +5 9 1 2 7 8 4 6 3 +7 8 4 3 5 6 2 1 9 +9 6 2 1 8 3 7 4 5 +3 4 5 9 6 7 8 2 1 +1 7 8 5 2 4 9 3 6 \ No newline at end of file diff --git a/challenges/sudoku/test/3/input.txt b/challenges/sudoku/test/3/input.txt new file mode 100644 index 0000000..c48043d --- /dev/null +++ b/challenges/sudoku/test/3/input.txt @@ -0,0 +1,9 @@ +0 7 0 0 0 0 0 0 9 +5 1 0 4 2 0 6 0 0 +0 8 0 3 0 0 7 0 0 +0 0 8 0 0 1 3 7 0 +0 2 3 0 8 0 0 4 0 +4 0 0 9 0 0 1 0 0 +9 6 2 8 0 0 0 3 0 +0 0 0 0 1 0 4 0 0 +7 0 0 2 0 3 0 9 6 \ No newline at end of file diff --git a/challenges/sudoku/test/3/output.txt b/challenges/sudoku/test/3/output.txt new file mode 100644 index 0000000..6f47bd5 --- /dev/null +++ b/challenges/sudoku/test/3/output.txt @@ -0,0 +1,9 @@ +3 7 4 1 6 8 2 5 9 +5 1 9 4 2 7 6 8 3 +2 8 6 3 9 5 7 1 4 +6 9 8 5 4 1 3 7 2 +1 2 3 7 8 6 9 4 5 +4 5 7 9 3 2 1 6 8 +9 6 2 8 7 4 5 3 1 +8 3 5 6 1 9 4 2 7 +7 4 1 2 5 3 8 9 6 \ No newline at end of file