Sudoku Solver Project
Sudoku Solver Project
Submitted by
I SEMESTER/ I YEAR
BONAFIDE CERTIFICATE
Certified that this project report titled PEER TO PEER CHAT APPLICATION is
the bonafide work of Mr. PARTHIV D PRABHU (RA241100302084),
Mr.ARUNKUMAR RATHINASABAPATHI ,(RA2411003020864)
Mr.AMITRAJEET PAUL (RA2411003020864 ) who carried out the project work
under my supervision. This Case study work confirms to 21CSS101J-
PROGRAMMING FOR PROBLEM SOLVING , I Semester, I year, 2024-2025
ODD Semester.
SIGNATURE
Dr.J.JOSPIN JEYA, M. E, Ph.D.,
Assistant Professor
Computer Science and Engineering,
SRM Institute of Science and Technology,
Ramapuram, Chennai.
TABLE OF CONTENT
S. No Content Page Number
1 Introduction
2 System Specification
2.1 Hardware Specification
2.2 Software Specification
3 Flow Diagram / Architecture Diagram
(Flowchart/algorithm)
4 Explanation of the working methodology
5 Source code
6 Output
7 Conclusion
8 References
.
INTRODUCTION OF THE PROJECT
PROBLEM STATEMENT:
The problem involves designing a program to generate and solve
Sudoku puzzles. A Sudoku puzzle is a 9x9 grid divided into nine 3x3
sub-grids, where some cells contain numbers (1-9) while others are
empty. The goal is to fill the grid such that each row, column, and 3x3
sub-grid contains unique numbers from 1 to 9. The program needs to
generate a valid puzzle with a unique solution and implement a
backtracking algorithm to solve it. Additionally, the grid must be
displayed in a formatted table for user readability.
SYSTEM REQUIREMENTS
import random
import copy
import tabulate
N=9
# Backtracking solver
def solveSudoku(grid, row=0, col=0):
if row == N - 1 and col == N:
return True
if col == N:
row += 1
col = 0
if grid[row][col] > 0:
return solveSudoku(grid, row, col + 1)
for num in range(1, N + 1):
if isSafe(grid, row, col, num):
grid[row][col] = num
if solveSudoku(grid, row, col + 1):
return True
grid[row][col] = 0
return False
def generate_full_grid():
grid = [[0 for _ in range(9)] for _ in range(9)]
def fill_grid(grid):
empty = find_empty(grid)
if not empty:
return True
row, col = empty
numbers = list(range(1, 10))
random.shuffle(numbers)
for num in numbers:
if is_valid(grid, num, (row, col)):
grid[row][col] = num
if fill_grid(grid):
return True
grid[row][col] = 0
return False
fill_grid(grid)
return grid
def generate_sudoku():
full_grid = generate_full_grid()
puzzle = remove_cells(full_grid)
return puzzle
# Main execution
if __name__ == "__main__":
# Generate a Sudoku puzzle
sudoku_puzzle = generate_sudoku()
print("Generated Sudoku Puzzle:")
print_grid(sudoku_puzzle)