This Python script checks whether a given Sudoku grid is valid according to standard Sudoku rules.It ensures that each row, column,and 3x3 sub-grid contains unique numbers(ignoring zeros, which represent empty cells).
- Python 3.x
- A text file (
sudoku.txt) containing the Sudoku grid you want to validate.- Each row must contain exactly 9 numbers, separated by spaces.
- The file must have exactly 9 rows.
Example sudoku.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
- The script reads the Sudoku grid from
sudoku.txt. - It checks each row, column, and 3x3 sub-grid for uniqueness (excluding zeros).
- If all rules are satisfied, the grid is considered valid.
- Place your Sudoku grid in a file named
sudoku.txtin the same folder as the script. - Run the script:
python sudoku_validator.py