-
-
Notifications
You must be signed in to change notification settings - Fork 46.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.") |
* Added algorithm to deeply clone a graph * Fixed file name and removed a function call * Removed nested function and fixed class parameter types * Fixed doctests * bug fix * Added class decorator * Updated doctests and fixed precommit errors * Cleaned up code * Simplified doctest * Added doctests * Code simplification * Created function which validates sudoku boards * Update matrix/validate_sudoku_board.py * Fixed precommit errors * Removed file accidentally included * Improved readability and simplicity * Add timeit benchmarks * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update validate_sudoku_board.py --------- Co-authored-by: Christian Clauss <cclauss@me.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Describe your change:
Checklist: