Sudoku Solver-1
Sudoku Solver-1
PROJECT NAME
SUDOKU SOLVER
Supervised By:
1. Prof. Hesham El-Deeb
Submitted By
Student Name
1) Omar Mahmoud Ahmed Khalil 97097
2) Mariam Homam Oyoun Alsoud 96816
3) Mohamed Ahmed Mahmoud Ahmed 98306
4) Omar Refaat Radwan Arfaa 97701
5) Esraa Atef Amen Amer 98993
6) Abdelrahman Ramadan Shaker Abdellahy 97273
7) Ali Mohamed Ali shahat 99358
8) Kholoud Youssef Tayel Abdelaty 98518
Chapter 1: Introduction
Sudoku is a globally renowned puzzle game renowned for its blend of simplicity and challenge,
making it a beloved pastime for puzzle enthusiasts worldwide. At its core, Sudoku revolves
around the goal of filling a 9x9 grid with digits from 1 to 9, ensuring that each column, row,
and 3x3 subgrid, often termed as "regions," contain all the digits without repetition.
The puzzle begins with a partially filled grid, with some cells already populated with numbers.
The player's objective is to strategically deduce and fill in the remaining cells logically,
ensuring that every digit fits into its proper place, satisfying the constraints of the game. These
constraints dictate that each digit must appear exactly once in every row, column, and 3x3
subgrid.
The allure of Sudoku lies in its scalability of difficulty, catering to a wide spectrum of players
from novices to seasoned veterans. The complexity of a Sudoku puzzle is determined by the
initial arrangement and placement of digits within the grid. While some puzzles may be
straightforward to solve, others can be notably challenging, requiring advanced problem-
solving strategies and logical deduction techniques.
In the realm of computer science, Sudoku serves as an excellent platform for exploring
constraint satisfaction techniques. This project aims to develop a program capable of efficiently
solving Sudoku puzzles through the systematic application of these techniques. By representing
the Sudoku puzzle as a Constraint Satisfaction Problem (CSP), the program navigates through
potential solutions while adhering strictly to the rules of the game. Through careful constraint
propagation and backtracking search algorithms, the program endeavors to explore and validate
potential solutions until a valid and complete Sudoku grid is achieved.
Chapter 2: System Analysis and Design
Functional Requirements:
• Input Handling: The system should be able to accept a partially filled 9x9 Sudoku grid
as input.
• Output Generation: Once a valid solution is found, the system should output the
completed Sudoku grid.
Non-Functional Requirements:
• Accuracy: The solver should guarantee correct solutions for all solvable Sudoku
puzzles.
• Usability: The program should have a user-friendly interface, allowing users to input
Sudoku puzzles easily and view the solution intuitively.
• Robustness: The system should handle invalid inputs gracefully and provide appropriate
error messages to the user.
• Scalability: The solver should be scalable to handle larger grid sizes or extended rule
sets if required in the future
Sequence Diagram
Use Case Diagram
Misuse Diagram
Activity Diagram
State Machine Diagram
Implementation Code
:- use_module(library(clpfd)).
% Predicate to solve a Sudoku puzzle
sudoku(Rows) :-
% Flatten the rows to a single list and restrict the domain to 1..9
append(Rows, Vs), Vs ins 1..9,
• sudoku/1 Predicate: Defines constraints for solving Sudoku. Ensures rows, columns,
and 3x3 subgrids have distinct digits.
• blocks/3 Predicate: Ensures each 3x3 subgrid contains distinct digits. Recursively
checks rows within each block.
• problem/2 Predicate: Defines Sudoku puzzles with identifiers and 9x9 grids. Empty
cells are represented as underscores.
• solve_sudoku/1 Predicate: Main entry point for solving Sudoku. Takes puzzle
identifier, retrieves it, solves using sudoku/1, labels variables, and prints the solution.
• labeling/2 Predicate: Assigns values from the domain to variables to satisfy constraints.
Used to label variables in the solved puzzle (with "First-Fail" heuristic).
Output