-
-
Notifications
You must be signed in to change notification settings - Fork 47.3k
Added validate sudoku board function #9881
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
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.") |
Describe your change:
Checklist: