Skip to content

Create Sudoku_Solver.py #10619

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

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions data_structures/arrays/sudoku_solver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
class Solution:
def solveSudoku(self, board: List[List[str]]) -> None:

Choose a reason for hiding this comment

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

As there is no test file in this pull request nor any test function or class in the file data_structures/arrays/sudoku_solver.py, please provide doctest for the function solveSudoku

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: solveSudoku

n = 9

def isValid(row, col, ch):

Choose a reason for hiding this comment

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

As there is no test file in this pull request nor any test function or class in the file data_structures/arrays/sudoku_solver.py, please provide doctest for the function isValid

Please provide return type hint for the function: isValid. If the function does not return a value, please provide the type hint as: def function() -> None:

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: isValid

Please provide type hint for the parameter: row

Please provide type hint for the parameter: col

Please provide type hint for the parameter: ch

row, col = int(row), int(col)

for i in range(9):
if board[i][col] == ch:
return False
if board[row][i] == ch:
return False

if board[3 * (row // 3) + i // 3][3 * (col // 3) + i % 3] == ch:
return False

return True

def solve(row, col):

Choose a reason for hiding this comment

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

As there is no test file in this pull request nor any test function or class in the file data_structures/arrays/sudoku_solver.py, please provide doctest for the function solve

Please provide return type hint for the function: solve. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: row

Please provide type hint for the parameter: col

if row == n:
return True
if col == n:
return solve(row + 1, 0)

if board[row][col] == ".":
for i in range(1, 10):
if isValid(row, col, str(i)):
board[row][col] = str(i)

if solve(row, col + 1):
return True
else:
board[row][col] = "."
return False
else:
return solve(row, col + 1)

solve(0, 0)


# do upvote if it helps.