Added validate sudoku board function#9881
Conversation
|
I think we already have this well covered. https://github.com/TheAlgorithms/Python/blob/master/backtracking/sudoku.py https://github.com/TheAlgorithms/Python/pulls?q=is%3Apr+sudoku |
|
Yeah, I saw this but I think validating a sudoku board is a materially different task than solving it. Happy to close this if you feel otherwise. |
|
You have two different files in this pull request. |
|
Old but nice ideas!! http://norvig.com/sudoku.html |
|
@cclauss was there anything else you wanted me to amend? |
matrix/validate_sudoku_board.py
Outdated
| NUM_ROWS = 9 | ||
| NUM_COLS = 9 | ||
| EMPTY_CELL = "." | ||
| IS_VALID = True |
There was a problem hiding this comment.
Let's use NUM_SQUARES instead of NUM_ROWS and NUM_ROWS.
Lets True and False in a boolean function.
| NUM_ROWS = 9 | |
| NUM_COLS = 9 | |
| EMPTY_CELL = "." | |
| IS_VALID = True | |
| NUM_SQUARES = 9 | |
| EMPTY_CELL = "." |
matrix/validate_sudoku_board.py
Outdated
| if len(sudoku_board) != NUM_ROWS: | ||
| raise Exception("Number of rows must be 9.") | ||
|
|
||
| for row in sudoku_board: | ||
| if len(row) != NUM_COLS: | ||
| raise Exception("Number of columns must be 9.") |
There was a problem hiding this comment.
| if len(sudoku_board) != NUM_ROWS: | |
| raise Exception("Number of rows must be 9.") | |
| for row in sudoku_board: | |
| if len(row) != NUM_COLS: | |
| raise Exception("Number of columns must be 9.") | |
| if len(sudoku_board) != NUM_SQUARES or any( | |
| len(row) != NUM_SQUARES for row in sudoku_board | |
| ): | |
| raise ValueError(f"Sudoku boards must be {NUM_SQUARES}x{NUM_SQUARES} squares.") |
Describe your change:
Checklist: