1
Department of Computer Science
Gujarat University
Ahmedabad - 380009
Sudoku solver
Presented By:
Fadia Pankti
Project Guide:
Dr. Nidhi Arora M.Sc.(AI & ML) – I
Project – I
December 2019
Table Of Contents
2
1.1 Objectives
1.2 Scope
1.3 What is Sudoku?
2.Problem Definition
3.Sudoku as constraint satisfaction problem
4. Solving methods
4.1 Brute force search methods
4.2 Backtracking
4.3 Forward checking
4.4 Constraint propagation
4.1 Brute force search methods
1. Introduction
5. Approach
6. Hardware & software requirements
7. Implementation
8. Testing & results
10. References
9. Conclusion & Future directions
Objectives
a) To solve Sudoku problem considering it as Constraint Satisfaction Problem
b) To get to the solution with minimum backtracking
c) To reach the goal state in least possible time
Index
3
Scope
4
 Recent Scope:
• Initially the board is given statically with different difficulty levels.
• Remove cells to create a valid Sudoku games according to the difficulty level that
is provided.
Index
What is Sudoku ?
• Sudoku is the Japanese abbreviation of a phrase meaning the digits must
remain single, where Su means number, doku which translates as single or
bachelor.
Variants
• Though the 9 × 9 grid with 3 × 3 inner boxes is by far the most common Sudoku
game, many other variants exist.
Index
5
Problem Definition
• A Sudoku puzzle is defined as a logic-based, number-
placement puzzle. The objective is to fill a 9×9 grid
with digits in such a way that each column, each row,
and each of the nine 3×3 grids that make up the
larger 9×9 grid contains all of the digits from 1 to 9.
Rule
• No number may appear more than once in any row
across, any column down, or within any small 9-box
square or omitted.(although, the can be repeated
along the diagonals).
Index
6
Sudoku As Constraint Satisfaction Problem
• A constraint satisfaction problem (CSP) is a problem that requires its solution
within some limitations/conditions also known as constraints. Sudoku is one them.
It consists of the following:
• A finite set of variables which stores the solution.
• A set of discrete values known as domain from which the solution is picked.
• A finite set of constraints.
Index
7
Continue…
 The idea:
• represent states as a vector of feature values. We have,
 k-features (or variables)
• Each feature takes a value.
Domain of possible values for the variables:
• height = {short, average, tall},
• weight = {light, average, heavy}.
• In CSPs, the problem is to search for a set of values for the features (variables) so that the
values satisfy some conditions (constraints).
Index
8
Example
Index
9
• Variables
- Each empty cells on grid
• Domain :
- Any Digits from1 to 9.
• Constraints :
- Same digit can't appear twice (or more) in
the same row.
- Same digit can't appear twice (or more) in
the same column.
- Same digit can't appear twice (or more) in
the same square.
Goal
Index
10
• Solutions are complete and consistent assignments
• E.g. every cell is filled with domain(1 to 9) and within
the constraints.
How to solve Sudoku ?
I. Brute Force Search Method
• BFS is one of the most general and basic techniques for searching for possible
solutions to a problem. The idea is that we want to generate every possible move
within the game and then test to see whether it solves our problem.
• the BFS algorithm visits the empty cells in some order, filling in digits sequentially
(from 1 to 9).
Index
11
Example
Index
12
Later step
II. Backtracking
• HOLD ON; what if a cell is discovered where none of the 9 digits is allowed?! …
• Well, then there’s a quick and easy solution to this call Backtracking.
• We should go back and change something in one of the previous cells and see if that works.
• Thus the algorithm will leave this unsolvable cell blank for now and move back i.e backtrack to
the previous cell.
• But it is exhaustive search and will take lot of time to reach to solution.
Index
13
Example Using Backtracking
Index
14
III. Forward checking
• The first improvement on backtracking search is forward checking.
• Keep track of remaining legal values for unassigned variables.
• It helps reducing the domain of the free variables that appears.
• For example, in Sudoku, each time a value is assigned to a variable, the value is removed from
the domain of the free variables that are either in the same line, in the same column or in the
same square as the assigned variable.
Index
15
Example Using Forward Checking
Index
16
IV. Constraint Propagation
Index
17
• place a four in the shaded box. It doesn't immediately
conflict with any other locations and after placing it all of
the squares still have possible values.
• Next look at the square right below the shaded one, it must be a two.
• Filling in a two there, however, leaves the lower left square
with no possible value.
• it only takes an extra two assignments to realize that the
four was wrong, but what if the two isn't the next one.
Continue…
• If the search is moving from left to right across the rows, it will assign the three
empty squares to the right of the shaded one first.
• Depending on the possible values that these squares
have, there may be up to three layers of branching before reaching the conflict.
• Each branch must now fail separately before the search realizes that the four
was a bad choice.
• The result is an increment in the time needed for the search to realize that
the four was a bad choice.
• The solution is to assign values that only have one possible choice immediately.
Index
18
Continue…
• In Constraint propagation we use the constraint to decrease the number of legal values for
a variable, which in turn could reduce the legal values for another variable, and so on
• In the example above after the four is assigned, constraint propagation realize that the space below
the four must be two. It then notices that the lower left corner has no possible value and fails,
returning to the search, which chooses another value for the shaded
square.
Index
19
Algorithm: Uses Backtracking
Index
20
function RECURSIVE - BACKTRACKING ( assignment, csp) returns a solution, or failure
if assignment is complete then return assignment
Var = SELECT-UNASSIGNED-VARIABLE (VARIABLES[csp], assignment, csp)
for each value in ORDER-DOMAIN-VALUES (var, assignment, csp) do
if value is consistent with assignment according to CONSTRAINTS [csp] then
add {var = value} to assignment
Result=RECURSIVE -BACKTRACKING(assignment, csp)
if result != failure then return result
remove {var = value} from assignment
return failure
Reference :[1]
Hardware & Software configuration
Index
21
Processor RAM Hard-disk
Pentium or
higher
512 MB or
higher
2GB or more
Technology Front End
Python (version 3.7) Pycharm
Hardware Configuration Software Configuration
Index
22
Result of brute force search method for easy puzzle
Initial state Goal state
Index
23
Result Of recursive backtracking method for easy puzzle
Initial state Goal state
Index
24
Result Of brute force search method for hard puzzle
Initial state Goal state
Index
25
Result Of recursive backtracking method for hard puzzle
Initial state Goal state
26
Conclusion & Future Directions
 Conclusion
• This study has shown that the Recursive backtracking algorithm is a feasible method to
solve any Sudoku puzzles. The algorithm is also an appropriate method to find a solution
faster and more efficient compared to the brute force algorithm.
• The proposed algorithm is able to solve such puzzles with any level of difficulties in a short
period of time. The performance of the Recursive backtracking algorithm is better than the
brute force algorithm with respect to the computing time to solve any puzzle.
• The brute force algorithm is guaranteed to have one solution. However, it does not adopt
intelligent strategies to solve the puzzles.
• This algorithm checks all possible solutions to the puzzle until a valid solution is found
which is a time-consuming procedure resulting an inefficient solver.
27
 Future Directions
 Implementing GUI to show generated puzzle and solved puzzle
board.
 Creating generator which can generate different puzzle,
providing different levels like hard, easy, medium.
Continue…
References
1. http://aima.cs.berkeley.edu/2nd-ed/newchap05.pdf
2. https://www.slideshare.net/TARUNKUMAR362/project-report-on-sudoku
3. https://www.ics.uci.edu/~yug10/uci/cs271/project/report/report.pdf
4. https://www.slideshare.net/yara2308/sudoku-38189890
5. https://steven.codes/blog/constraint-satisfaction-with-sudoku/
6. https://www.codeproject.com/Articles/34403/Sudoku-as-a-CSP
7. https://norvig.com/sudoku.html
8. https://www.slideshare.net/sohamkoolkarni/compsci271-a-
fall2016sudokusolverprojectreport
Index
28
References
Thank you
29

More Related Content

PDF
Autoencoder
PDF
Sudoku Solver
PPSX
Intelligent Sudoku Solver
PDF
Sudokureport
PDF
Lec 3 knowledge acquisition representation and inference
PPTX
Introduction to Genetic Algorithms
PDF
Introduction to Autoencoders
PPTX
AI3391 Artificial Intelligence Session 20 partially observed games.pptx
Autoencoder
Sudoku Solver
Intelligent Sudoku Solver
Sudokureport
Lec 3 knowledge acquisition representation and inference
Introduction to Genetic Algorithms
Introduction to Autoencoders
AI3391 Artificial Intelligence Session 20 partially observed games.pptx

What's hot (20)

PPTX
Soft computing01
PPTX
Autoencoder
PPTX
Applications of hybrid systems
PPT
Artificial Neural Networks - ANN
PPT
PPTX
AI_Session 3 Problem Solving Agent and searching for solutions.pptx
PPT
Facts finding techniques in Database
PDF
NLP with Deep Learning
PPTX
Deep learning
ODP
Simple Introduction to AutoEncoder
PPTX
Introduction to CNN
PDF
Graph Based Clustering
PDF
Heuristic search
PPTX
Ariane 5 launcher failure - why did it happen
PPTX
Expert system
PPT
Version spaces
PPT
Knowledge Representation in Artificial intelligence
PPTX
PDF
Autoencoders
PPTX
Basics of Soft Computing
Soft computing01
Autoencoder
Applications of hybrid systems
Artificial Neural Networks - ANN
AI_Session 3 Problem Solving Agent and searching for solutions.pptx
Facts finding techniques in Database
NLP with Deep Learning
Deep learning
Simple Introduction to AutoEncoder
Introduction to CNN
Graph Based Clustering
Heuristic search
Ariane 5 launcher failure - why did it happen
Expert system
Version spaces
Knowledge Representation in Artificial intelligence
Autoencoders
Basics of Soft Computing
Ad

Similar to Sudoku solver (20)

PPT
Sudoku
PDF
Andrew Daws - Final Project Report
PPTX
Sudoku solver ppt
PPTX
Solve Sudoku using Constraint Propagation- Search and Genetic Algorithm
PPTX
PPTX
AIw10_Backtracking.pptx
PPTX
final presentation of sudoku solver project
PDF
7-Backtracking.pdfsssssssssssssssssssssssssssssssssss
PPT
05-constraint-satisfaction-problems-(us).ppt
PPT
BackTracking Algorithm: Technique and Examples
PDF
Skiena algorithm 2007 lecture15 backtracing
PPTX
Sudoku solver ppt with exquisite example and build.pptx
PPTX
python presentation.pptx which includes project details
PPT
constraintSat.ppt
PPTX
Genetic operators
PDF
P1
PDF
Artificial Intelligence JNTUH Syllabusss
PPTX
Backtracking in Data Structure and Algorithm
Sudoku
Andrew Daws - Final Project Report
Sudoku solver ppt
Solve Sudoku using Constraint Propagation- Search and Genetic Algorithm
AIw10_Backtracking.pptx
final presentation of sudoku solver project
7-Backtracking.pdfsssssssssssssssssssssssssssssssssss
05-constraint-satisfaction-problems-(us).ppt
BackTracking Algorithm: Technique and Examples
Skiena algorithm 2007 lecture15 backtracing
Sudoku solver ppt with exquisite example and build.pptx
python presentation.pptx which includes project details
constraintSat.ppt
Genetic operators
P1
Artificial Intelligence JNTUH Syllabusss
Backtracking in Data Structure and Algorithm
Ad

Recently uploaded (20)

PDF
Introduction to Data Science and Data Analysis
PDF
Systems Analysis and Design, 12th Edition by Scott Tilley Test Bank.pdf
PPTX
A Complete Guide to Streamlining Business Processes
PPTX
SET 1 Compulsory MNH machine learning intro
PDF
Tetra Pak Index 2023 - The future of health and nutrition - Full report.pdf
PPT
lectureusjsjdhdsjjshdshshddhdhddhhd1.ppt
PPTX
FMIS 108 and AISlaudon_mis17_ppt_ch11.pptx
PDF
REAL ILLUMINATI AGENT IN KAMPALA UGANDA CALL ON+256765750853/0705037305
PDF
Data Engineering Interview Questions & Answers Data Modeling (3NF, Star, Vaul...
PPT
DU, AIS, Big Data and Data Analytics.ppt
PDF
Votre score augmente si vous choisissez une catégorie et que vous rédigez une...
PPTX
Copy of 16 Timeline & Flowchart Templates – HubSpot.pptx
PPTX
chrmotography.pptx food anaylysis techni
PPTX
CYBER SECURITY the Next Warefare Tactics
PDF
[EN] Industrial Machine Downtime Prediction
PDF
Optimise Shopper Experiences with a Strong Data Estate.pdf
PPTX
Leprosy and NLEP programme community medicine
PPT
statistic analysis for study - data collection
PPTX
Introduction to Inferential Statistics.pptx
PPTX
DS-40-Pre-Engagement and Kickoff deck - v8.0.pptx
Introduction to Data Science and Data Analysis
Systems Analysis and Design, 12th Edition by Scott Tilley Test Bank.pdf
A Complete Guide to Streamlining Business Processes
SET 1 Compulsory MNH machine learning intro
Tetra Pak Index 2023 - The future of health and nutrition - Full report.pdf
lectureusjsjdhdsjjshdshshddhdhddhhd1.ppt
FMIS 108 and AISlaudon_mis17_ppt_ch11.pptx
REAL ILLUMINATI AGENT IN KAMPALA UGANDA CALL ON+256765750853/0705037305
Data Engineering Interview Questions & Answers Data Modeling (3NF, Star, Vaul...
DU, AIS, Big Data and Data Analytics.ppt
Votre score augmente si vous choisissez une catégorie et que vous rédigez une...
Copy of 16 Timeline & Flowchart Templates – HubSpot.pptx
chrmotography.pptx food anaylysis techni
CYBER SECURITY the Next Warefare Tactics
[EN] Industrial Machine Downtime Prediction
Optimise Shopper Experiences with a Strong Data Estate.pdf
Leprosy and NLEP programme community medicine
statistic analysis for study - data collection
Introduction to Inferential Statistics.pptx
DS-40-Pre-Engagement and Kickoff deck - v8.0.pptx

Sudoku solver

  • 1. 1 Department of Computer Science Gujarat University Ahmedabad - 380009 Sudoku solver Presented By: Fadia Pankti Project Guide: Dr. Nidhi Arora M.Sc.(AI & ML) – I Project – I December 2019
  • 2. Table Of Contents 2 1.1 Objectives 1.2 Scope 1.3 What is Sudoku? 2.Problem Definition 3.Sudoku as constraint satisfaction problem 4. Solving methods 4.1 Brute force search methods 4.2 Backtracking 4.3 Forward checking 4.4 Constraint propagation 4.1 Brute force search methods 1. Introduction 5. Approach 6. Hardware & software requirements 7. Implementation 8. Testing & results 10. References 9. Conclusion & Future directions
  • 3. Objectives a) To solve Sudoku problem considering it as Constraint Satisfaction Problem b) To get to the solution with minimum backtracking c) To reach the goal state in least possible time Index 3
  • 4. Scope 4  Recent Scope: • Initially the board is given statically with different difficulty levels. • Remove cells to create a valid Sudoku games according to the difficulty level that is provided. Index
  • 5. What is Sudoku ? • Sudoku is the Japanese abbreviation of a phrase meaning the digits must remain single, where Su means number, doku which translates as single or bachelor. Variants • Though the 9 × 9 grid with 3 × 3 inner boxes is by far the most common Sudoku game, many other variants exist. Index 5
  • 6. Problem Definition • A Sudoku puzzle is defined as a logic-based, number- placement puzzle. The objective is to fill a 9×9 grid with digits in such a way that each column, each row, and each of the nine 3×3 grids that make up the larger 9×9 grid contains all of the digits from 1 to 9. Rule • No number may appear more than once in any row across, any column down, or within any small 9-box square or omitted.(although, the can be repeated along the diagonals). Index 6
  • 7. Sudoku As Constraint Satisfaction Problem • A constraint satisfaction problem (CSP) is a problem that requires its solution within some limitations/conditions also known as constraints. Sudoku is one them. It consists of the following: • A finite set of variables which stores the solution. • A set of discrete values known as domain from which the solution is picked. • A finite set of constraints. Index 7
  • 8. Continue…  The idea: • represent states as a vector of feature values. We have,  k-features (or variables) • Each feature takes a value. Domain of possible values for the variables: • height = {short, average, tall}, • weight = {light, average, heavy}. • In CSPs, the problem is to search for a set of values for the features (variables) so that the values satisfy some conditions (constraints). Index 8
  • 9. Example Index 9 • Variables - Each empty cells on grid • Domain : - Any Digits from1 to 9. • Constraints : - Same digit can't appear twice (or more) in the same row. - Same digit can't appear twice (or more) in the same column. - Same digit can't appear twice (or more) in the same square.
  • 10. Goal Index 10 • Solutions are complete and consistent assignments • E.g. every cell is filled with domain(1 to 9) and within the constraints.
  • 11. How to solve Sudoku ? I. Brute Force Search Method • BFS is one of the most general and basic techniques for searching for possible solutions to a problem. The idea is that we want to generate every possible move within the game and then test to see whether it solves our problem. • the BFS algorithm visits the empty cells in some order, filling in digits sequentially (from 1 to 9). Index 11
  • 13. II. Backtracking • HOLD ON; what if a cell is discovered where none of the 9 digits is allowed?! … • Well, then there’s a quick and easy solution to this call Backtracking. • We should go back and change something in one of the previous cells and see if that works. • Thus the algorithm will leave this unsolvable cell blank for now and move back i.e backtrack to the previous cell. • But it is exhaustive search and will take lot of time to reach to solution. Index 13
  • 15. III. Forward checking • The first improvement on backtracking search is forward checking. • Keep track of remaining legal values for unassigned variables. • It helps reducing the domain of the free variables that appears. • For example, in Sudoku, each time a value is assigned to a variable, the value is removed from the domain of the free variables that are either in the same line, in the same column or in the same square as the assigned variable. Index 15
  • 16. Example Using Forward Checking Index 16
  • 17. IV. Constraint Propagation Index 17 • place a four in the shaded box. It doesn't immediately conflict with any other locations and after placing it all of the squares still have possible values. • Next look at the square right below the shaded one, it must be a two. • Filling in a two there, however, leaves the lower left square with no possible value. • it only takes an extra two assignments to realize that the four was wrong, but what if the two isn't the next one.
  • 18. Continue… • If the search is moving from left to right across the rows, it will assign the three empty squares to the right of the shaded one first. • Depending on the possible values that these squares have, there may be up to three layers of branching before reaching the conflict. • Each branch must now fail separately before the search realizes that the four was a bad choice. • The result is an increment in the time needed for the search to realize that the four was a bad choice. • The solution is to assign values that only have one possible choice immediately. Index 18
  • 19. Continue… • In Constraint propagation we use the constraint to decrease the number of legal values for a variable, which in turn could reduce the legal values for another variable, and so on • In the example above after the four is assigned, constraint propagation realize that the space below the four must be two. It then notices that the lower left corner has no possible value and fails, returning to the search, which chooses another value for the shaded square. Index 19
  • 20. Algorithm: Uses Backtracking Index 20 function RECURSIVE - BACKTRACKING ( assignment, csp) returns a solution, or failure if assignment is complete then return assignment Var = SELECT-UNASSIGNED-VARIABLE (VARIABLES[csp], assignment, csp) for each value in ORDER-DOMAIN-VALUES (var, assignment, csp) do if value is consistent with assignment according to CONSTRAINTS [csp] then add {var = value} to assignment Result=RECURSIVE -BACKTRACKING(assignment, csp) if result != failure then return result remove {var = value} from assignment return failure Reference :[1]
  • 21. Hardware & Software configuration Index 21 Processor RAM Hard-disk Pentium or higher 512 MB or higher 2GB or more Technology Front End Python (version 3.7) Pycharm Hardware Configuration Software Configuration
  • 22. Index 22 Result of brute force search method for easy puzzle Initial state Goal state
  • 23. Index 23 Result Of recursive backtracking method for easy puzzle Initial state Goal state
  • 24. Index 24 Result Of brute force search method for hard puzzle Initial state Goal state
  • 25. Index 25 Result Of recursive backtracking method for hard puzzle Initial state Goal state
  • 26. 26 Conclusion & Future Directions  Conclusion • This study has shown that the Recursive backtracking algorithm is a feasible method to solve any Sudoku puzzles. The algorithm is also an appropriate method to find a solution faster and more efficient compared to the brute force algorithm. • The proposed algorithm is able to solve such puzzles with any level of difficulties in a short period of time. The performance of the Recursive backtracking algorithm is better than the brute force algorithm with respect to the computing time to solve any puzzle. • The brute force algorithm is guaranteed to have one solution. However, it does not adopt intelligent strategies to solve the puzzles. • This algorithm checks all possible solutions to the puzzle until a valid solution is found which is a time-consuming procedure resulting an inefficient solver.
  • 27. 27  Future Directions  Implementing GUI to show generated puzzle and solved puzzle board.  Creating generator which can generate different puzzle, providing different levels like hard, easy, medium. Continue…
  • 28. References 1. http://aima.cs.berkeley.edu/2nd-ed/newchap05.pdf 2. https://www.slideshare.net/TARUNKUMAR362/project-report-on-sudoku 3. https://www.ics.uci.edu/~yug10/uci/cs271/project/report/report.pdf 4. https://www.slideshare.net/yara2308/sudoku-38189890 5. https://steven.codes/blog/constraint-satisfaction-with-sudoku/ 6. https://www.codeproject.com/Articles/34403/Sudoku-as-a-CSP 7. https://norvig.com/sudoku.html 8. https://www.slideshare.net/sohamkoolkarni/compsci271-a- fall2016sudokusolverprojectreport Index 28 References