1
1
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:
Divlo 2021-07-06 15:59:01 +02:00
parent c80eb11874
commit 08ba65ad6e
No known key found for this signature in database
GPG Key ID: 185ED2F15F104E52
8 changed files with 111 additions and 0 deletions

View 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
```

View File

View 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 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