mirror of
https://github.com/theoludwig/programming-challenges.git
synced 2024-12-08 00:45:29 +01:00
feat(challenges): add sudoku
This commit is contained in:
parent
c80eb11874
commit
08ba65ad6e
57
challenges/sudoku/README.md
Normal file
57
challenges/sudoku/README.md
Normal file
@ -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
|
||||
```
|
0
challenges/sudoku/solutions/.gitkeep
Normal file
0
challenges/sudoku/solutions/.gitkeep
Normal file
9
challenges/sudoku/test/1/input.txt
Normal file
9
challenges/sudoku/test/1/input.txt
Normal file
@ -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
|
9
challenges/sudoku/test/1/output.txt
Normal file
9
challenges/sudoku/test/1/output.txt
Normal file
@ -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
|
9
challenges/sudoku/test/2/input.txt
Normal file
9
challenges/sudoku/test/2/input.txt
Normal file
@ -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
|
9
challenges/sudoku/test/2/output.txt
Normal file
9
challenges/sudoku/test/2/output.txt
Normal file
@ -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
|
9
challenges/sudoku/test/3/input.txt
Normal file
9
challenges/sudoku/test/3/input.txt
Normal file
@ -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
|
9
challenges/sudoku/test/3/output.txt
Normal file
9
challenges/sudoku/test/3/output.txt
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user