Skip to content

Added validate sudoku board function - #9881

Merged
cclauss merged 19 commits into
TheAlgorithms:masterfrom
dbring:validate-sudoku-board
Oct 14, 2023
Merged

Added validate sudoku board function#9881
cclauss merged 19 commits into
TheAlgorithms:masterfrom
dbring:validate-sudoku-board

Conversation

@dbring

Copy link
Copy Markdown
Contributor

Describe your change:

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

@algorithms-keeperalgorithms-keeperBot added awaiting reviews This PR is ready to be reviewed tests are failing Do not merge until tests pass labels Oct 5, 2023
@cclauss

Copy link
Copy Markdown
Member

Comment threadmatrix/validate_sudoku_board.py Outdated
@cclauss

Copy link
Copy Markdown
Member
mypy.....................................................................Failed
- hook id: mypy
- exit code: 1
matrix/validate_sudoku_board.py:77: error: Need type annotation for "row_values" [var-annotated]
matrix/validate_sudoku_board.py:78: error: Need type annotation for "col_values" [var-annotated]
matrix/validate_sudoku_board.py:79: error: Need type annotation for "box_values" [var-annotated]
matrix/validate_sudoku_board.py:81: error: Incompatible types in assignment (expression has type "int", variable has type "list[str]") [assignment]
matrix/validate_sudoku_board.py:83: error: No overload variant of "__getitem__" of "list" matches argument type "list[str]" [call-overload]
matrix/validate_sudoku_board.py:83: note: Possible overload variants:
matrix/validate_sudoku_board.py:83: note: def __getitem__(self, SupportsIndex, /) -> list[str]
matrix/validate_sudoku_board.py:83: note: def __getitem__(self, slice, /) -> list[list[str]]
matrix/validate_sudoku_board.py:88: error: Unsupported operand types for // ("list[str]" and "int") [operator]
Found 6 errors in 1 file (checked 1211 source files)

@dbring

Copy link
Copy Markdown
ContributorAuthor

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.

@algorithms-keeperalgorithms-keeperBot removed the tests are failing Do not merge until tests pass label Oct 6, 2023
@cclauss

Copy link
Copy Markdown
Member

You have two different files in this pull request.

@cclauss

Copy link
Copy Markdown
Member

Old but nice ideas!! http://norvig.com/sudoku.html

@dbring

Copy link
Copy Markdown
ContributorAuthor

@cclauss was there anything else you wanted me to amend?

Comment threadmatrix/validate_sudoku_board.py Outdated
Comment on lines +24 to +27
NUM_ROWS = 9
NUM_COLS = 9
EMPTY_CELL = "."
IS_VALID = True

Copy link
Copy Markdown
Member

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.

Suggested change
NUM_ROWS=9
NUM_COLS=9
EMPTY_CELL="."
IS_VALID=True
NUM_SQUARES=9
EMPTY_CELL="."

Comment threadmatrix/validate_sudoku_board.py Outdated
Comment on lines +70 to +75
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.")

@cclausscclaussOct 9, 2023

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
iflen(sudoku_board) !=NUM_ROWS:
raiseException("Number of rows must be 9.")
forrowinsudoku_board:
iflen(row) !=NUM_COLS:
raiseException("Number of columns must be 9.")
iflen(sudoku_board) !=NUM_SQUARESorany(
len(row) !=NUM_SQUARESforrowinsudoku_board
):
raiseValueError(f"Sudoku boards must be {NUM_SQUARES}x{NUM_SQUARES} squares.")

Comment threadmatrix/validate_sudoku_board.py Outdated
@algorithms-keeperalgorithms-keeperBot added awaiting changes A maintainer has requested changes to this PR and removed awaiting reviews This PR is ready to be reviewed labels Oct 9, 2023
@algorithms-keeperalgorithms-keeperBot removed the awaiting changes A maintainer has requested changes to this PR label Oct 9, 2023
@algorithms-keeperalgorithms-keeperBot added the awaiting reviews This PR is ready to be reviewed label Oct 9, 2023
@dbring
dbring requested a review from cclaussOctober 13, 2023 19:01
@algorithms-keeperalgorithms-keeperBot added the tests are failing Do not merge until tests pass label Oct 14, 2023
@cclauss
cclauss enabled auto-merge (squash) October 14, 2023 15:34
@algorithms-keeperalgorithms-keeperBot removed the tests are failing Do not merge until tests pass label Oct 14, 2023
@cclauss
cclauss merged commit 212cdfe into TheAlgorithms:masterOct 14, 2023
@algorithms-keeperalgorithms-keeperBot removed the awaiting reviews This PR is ready to be reviewed label Oct 14, 2023
@isidroasisidroas mentioned this pull request Jan 25, 2025
14 tasks
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@dbring@cclauss