0% found this document useful (0 votes)
2 views

Suduko Solver Python

The document contains Python code for solving a Sudoku puzzle using a backtracking algorithm. It defines two functions: 'is_valid' to check if a number can be placed in a specific position, and 'solve_sudoku' to recursively fill the board. The board is represented as a 2D list, with '0' indicating empty cells.

Uploaded by

Suresh Bonam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Suduko Solver Python

The document contains Python code for solving a Sudoku puzzle using a backtracking algorithm. It defines two functions: 'is_valid' to check if a number can be placed in a specific position, and 'solve_sudoku' to recursively fill the board. The board is represented as a 2D list, with '0' indicating empty cells.

Uploaded by

Suresh Bonam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

def is_valid(board, row, col, num):

for x in range(9):

if board[row][x] == num or board[x][col] == num:

return False

start_row, start_col = 3 * (row // 3), 3 * (col // 3)

for i in range(3):

for j in range(3):

if board[start_row + i][start_col + j] == num:

return False

return True

def solve_sudoku(board):

for row in range(9):

for col in range(9):

if board[row][col] == 0:

for num in range(1, 10):

if is_valid(board, row, col, num):

board[row][col] = num

if solve_sudoku(board):

return True

board[row][col] = 0

return False

return True

board = [

[5, 3, 0, 0, 7, 0, 0, 0, 0],

You might also like