Digi-Sudoku
- Manish Panchmatia
- https://github.com/mpanchmatia/Digi-Sudoku
Agenda
• Why name : “Digi-Sudoku” ?
• Overall Architecture
• Finite State Machine
• Use Cases and Execution Flow
• Naming Convention
• References
• Questions - Answers
Why name : “Digi-Sudoku” ?
• Root: Digital Electronics
• My github repository
– https://github.com/mpanchmatia/TabulationMethod
– Quine–McCluskey algorithm (‘Tabulation Method’)
– To design digital circuit with AND and OR gates
• The candidate values are stored as bitmap for
empty cells. Bitmaps and bitwise operators
optimize memory utilization.
Agenda
• Why name : “Digi-Sudoku” ?
• Overall Architecture
• Finite State Machine
• Use Cases and Execution Flow
• Naming Convention
• References
• Questions - Answers
Overall Architecture
HTML
templates
Python
Algorithms
Jinja2
Python
Flask
Future Scope
• The architecture can be expanded as full-
fledged website / mobile app, with user
authentication, competition, prizes, usage
analytics etc.
• The solution can be modified to deploy on
micro-service based, server-less architecture.
• Sudoku puzzles can be stored in database with
its various attributes like category (easy,
medium, hard), comments, hints, popularity etc.
Agenda
• Why name : “Digi-Sudoku” ?
• Overall Architecture
• Finite State Machine
• Use Cases and Execution Flow
• Naming Convention
• References
• Questions - Answers
Approach : Human
• There are some basic techniques, advance
techniques and expert techniques to solve
Sudoku
• Expert Techniques are more suitable for human
with visual analysis of the Sudoku grid
– The XWing Techniques
– The Swordfish Techniques
– etc.
Approach : Computer Software
• Computer algorithm can use ‘burst force’
approach by evaluating all possible values for all
empty solution. It will more CPU & memory
intensive, due to its iterative process.
• The best possible software approach can be
combination of ‘burst force’ and other
techniques
Approach : Digi-Sudoku
• The ‘Digi-Sudoku’ application implements some
of the basic techniques and advance techniques
– Function Zero: SingleCandidate
– Function One: ExplicitRegion
– Function Two: ImplicitRegion
– Function Three: CandidateLineTechnique
– Function Four: MultipleLinesTechnique
• These techniques are called in sequence as per
FSM
Finite State Machine
Single
Candidate
Function
One
Function
Two
Function
N - 1
Function
N - 1
OK
Error
Init
Progress
No Progress
Future Scope
• The ‘Digi-Sudoku’ application can be extended
with additional sophisticated algorithms
• Some heuristic rules can be also added to
choose appropriate algorithm
• The FSM flow can be optimized. For example:
every time, going back to ‘candidate algorithm’
can be avoided
Agenda
• Why name : “Digi-Sudoku” ?
• Overall Architecture
• Finite State Machine
• Use Cases and Execution Flow
• Naming Convention
• References
• Questions - Answers
Use Cases
For End-User
• Add new Sudoku puzzle
• Display randomly selected Sudoku puzzle
• Display specific Sudoku puzzle
• Solve Sudoku puzzle
For Developer
• Display all Sudoku puzzles
• Test all Sudoku puzzles
– Unit Testing
– Performance Measurement
Execution Flow : End-User
Home :
index.html
Add:
add_sudoku.html
Submit:
submit_sudoku.html
New:
new_sudoku.html
Solve:
solve_sudoku.html
Add
new
Sudoku
puzzle
Submit
new
Sudoku
puzzle
Display
newly
added
Sudoku
puzzle
Solve
Sudoku puzzle
Display
randomly
selected
Sudoku
puzzle
Display
specific
Sudoku
puzzle
Display
randomly
selected
Sudoku
puzzle
Add new
Sudoku puzzle
Future Scope
• The ‘Digi-Sudoku’ application can be enhanced
with more UI and UX features
• The application can reveal value for specific
empty cell, as per user’s request as hint
• The application can allow user to solve the
Sudoku puzzle.
• The application can allow user to add candidate
values for empty cell.
• Better error handling and error reporting.
Execution Flow : Developer
Unit Testing and Performance Measurement
• After uncommenting PrintOptions function:
http://<host:port>/test_all can be invoked
• The test case pass / fail summary will be
displayed in browser
• Further debugging is possible from console log
• The additional code can be instrumented for
performance measurement.
Execution Flow : Developer
Accessing all Sudoku Puzzles
Display All:
display_all.html
Solve:
solve_sudoku.html
Solve
Sudoku puzzle
Display all
Sudoku
puzzle
Display
selected
Sudoku
Puzzle from URL
New:
new_sudoku.html
Browser Back Button
Display
randomly
selected
Sudoku
puzzle
Agenda
• Why name : “Digi-Sudoku” ?
• Overall Architecture
• Finite State Machine
• Use Cases and Execution Flow
• Naming Convention
• References
• Questions - Answers
Variables
• Region is collection of cells
• Region = Block | Line
• Line = Row | Column
• Region is defined as list of cellIndex
listCellIndexInRegion
• blockIndex, rowIndex and
columnIndex range is 0 to 8
• cellIndex range is 0 to 80
• digit range is 1 to 9
Variables
• The member variable options is a dictionary
with cellIndex as key and bitmap for all
possible candidate values
• The member variable output is also a
dictionary with cellIndex as key and final
single value for that specific cell.
• Some helper functions create a reverse map
dicDigit with digit as key and list of all
cellIndex having that digit.
Class
• Sudoku is abstract base class
• It has abstract methods
– Solve
– Load
• ClassicSudoku is concreate class for 9 x 9
Classical Sudoku
• ClassicSudoku class has specific static
variables
–size = 9
–invert = 1022 etc.
Class
• ClassicSudoku class has specific static
methods
– GetRowIndex
– GetColumnIndex
– GetBlockIndex
• These method takes cellIndex as input
parameter and return index for specific region
Algorithm Methods
• Each algorithm is implemented as function
Solve<Algorithm Name>
• Most of the algorithms has helper function to
work on given region with name
<Algorithm Name>SolveARegion
Future Scope
• The abstract base class Sudoku can be
extended for different size of Sudoku puzzles
– Mini Sudoku for kids 4 x 4
– Super Sudoku 12 x 12
– Giant Sudoku 15 x 15
– Monster Sudoku 25 x 25
• The GetBlockIndex method can be
modified to support Irregular Sudoku
Future Scope
• The abstract base class Sudoku can be
extended for different types of Sudoku puzzles
– Trio Sudoku
– Odd-Even Sudoku
– Consecutive Sudoku
– Diagonal Sudoku
– Irregular Sudoku
– Kakurofied Sudoku etc.
Agenda
• Why name : “Digi-Sudoku” ?
• Overall Architecture
• Finite State Machine
• Use Cases and Execution Flow
• Naming Convention
• References
• Questions - Answers
Reference
• Book : “A to Z of Sudoku. Science behind
Sudoku”
– by Narendra Jussien
– ISBN: 8130908573
– ISBN13: 9788130908571
Reference
• Book : “Times Book of Gen-X Sudoku”
– https://www.amazon.in/Times-Gen-X-Sudoku-
Mohanlal-Naresh/dp/8189906046
– ISBN-10: 8189906046
– ISBN-13: 978-8189906047
Reference
• CSS Style from github
<style type="text/css">
table {
margin:1em auto;
}
td {
height:30px;
width:30px;
border:1px solid;
text-align:center;
}
td:first-child {
border-left:solid;
}
td:nth-child(3n) {
border-right:solid ;
}
tr:first-child {
border-top:solid;
}
tr:nth-child(3n) td {
border-bottom:solid ;
}
</style>
Agenda
• Why name : “Digi-Sudoku” ?
• Overall Architecture
• Finite State Machine
• Use Cases and Execution Flow
• Naming Convention
• References
• Questions - Answers
Question - Answer
Thank You

Digi sudoku

  • 1.
    Digi-Sudoku - Manish Panchmatia -https://github.com/mpanchmatia/Digi-Sudoku
  • 2.
    Agenda • Why name: “Digi-Sudoku” ? • Overall Architecture • Finite State Machine • Use Cases and Execution Flow • Naming Convention • References • Questions - Answers
  • 3.
    Why name :“Digi-Sudoku” ? • Root: Digital Electronics • My github repository – https://github.com/mpanchmatia/TabulationMethod – Quine–McCluskey algorithm (‘Tabulation Method’) – To design digital circuit with AND and OR gates • The candidate values are stored as bitmap for empty cells. Bitmaps and bitwise operators optimize memory utilization.
  • 4.
    Agenda • Why name: “Digi-Sudoku” ? • Overall Architecture • Finite State Machine • Use Cases and Execution Flow • Naming Convention • References • Questions - Answers
  • 5.
  • 6.
    Future Scope • Thearchitecture can be expanded as full- fledged website / mobile app, with user authentication, competition, prizes, usage analytics etc. • The solution can be modified to deploy on micro-service based, server-less architecture. • Sudoku puzzles can be stored in database with its various attributes like category (easy, medium, hard), comments, hints, popularity etc.
  • 7.
    Agenda • Why name: “Digi-Sudoku” ? • Overall Architecture • Finite State Machine • Use Cases and Execution Flow • Naming Convention • References • Questions - Answers
  • 8.
    Approach : Human •There are some basic techniques, advance techniques and expert techniques to solve Sudoku • Expert Techniques are more suitable for human with visual analysis of the Sudoku grid – The XWing Techniques – The Swordfish Techniques – etc.
  • 9.
    Approach : ComputerSoftware • Computer algorithm can use ‘burst force’ approach by evaluating all possible values for all empty solution. It will more CPU & memory intensive, due to its iterative process. • The best possible software approach can be combination of ‘burst force’ and other techniques
  • 10.
    Approach : Digi-Sudoku •The ‘Digi-Sudoku’ application implements some of the basic techniques and advance techniques – Function Zero: SingleCandidate – Function One: ExplicitRegion – Function Two: ImplicitRegion – Function Three: CandidateLineTechnique – Function Four: MultipleLinesTechnique • These techniques are called in sequence as per FSM
  • 11.
    Finite State Machine Single Candidate Function One Function Two Function N- 1 Function N - 1 OK Error Init Progress No Progress
  • 12.
    Future Scope • The‘Digi-Sudoku’ application can be extended with additional sophisticated algorithms • Some heuristic rules can be also added to choose appropriate algorithm • The FSM flow can be optimized. For example: every time, going back to ‘candidate algorithm’ can be avoided
  • 13.
    Agenda • Why name: “Digi-Sudoku” ? • Overall Architecture • Finite State Machine • Use Cases and Execution Flow • Naming Convention • References • Questions - Answers
  • 14.
    Use Cases For End-User •Add new Sudoku puzzle • Display randomly selected Sudoku puzzle • Display specific Sudoku puzzle • Solve Sudoku puzzle For Developer • Display all Sudoku puzzles • Test all Sudoku puzzles – Unit Testing – Performance Measurement
  • 15.
    Execution Flow :End-User Home : index.html Add: add_sudoku.html Submit: submit_sudoku.html New: new_sudoku.html Solve: solve_sudoku.html Add new Sudoku puzzle Submit new Sudoku puzzle Display newly added Sudoku puzzle Solve Sudoku puzzle Display randomly selected Sudoku puzzle Display specific Sudoku puzzle Display randomly selected Sudoku puzzle Add new Sudoku puzzle
  • 16.
    Future Scope • The‘Digi-Sudoku’ application can be enhanced with more UI and UX features • The application can reveal value for specific empty cell, as per user’s request as hint • The application can allow user to solve the Sudoku puzzle. • The application can allow user to add candidate values for empty cell. • Better error handling and error reporting.
  • 17.
    Execution Flow :Developer Unit Testing and Performance Measurement • After uncommenting PrintOptions function: http://<host:port>/test_all can be invoked • The test case pass / fail summary will be displayed in browser • Further debugging is possible from console log • The additional code can be instrumented for performance measurement.
  • 18.
    Execution Flow :Developer Accessing all Sudoku Puzzles Display All: display_all.html Solve: solve_sudoku.html Solve Sudoku puzzle Display all Sudoku puzzle Display selected Sudoku Puzzle from URL New: new_sudoku.html Browser Back Button Display randomly selected Sudoku puzzle
  • 19.
    Agenda • Why name: “Digi-Sudoku” ? • Overall Architecture • Finite State Machine • Use Cases and Execution Flow • Naming Convention • References • Questions - Answers
  • 20.
    Variables • Region iscollection of cells • Region = Block | Line • Line = Row | Column • Region is defined as list of cellIndex listCellIndexInRegion • blockIndex, rowIndex and columnIndex range is 0 to 8 • cellIndex range is 0 to 80 • digit range is 1 to 9
  • 21.
    Variables • The membervariable options is a dictionary with cellIndex as key and bitmap for all possible candidate values • The member variable output is also a dictionary with cellIndex as key and final single value for that specific cell. • Some helper functions create a reverse map dicDigit with digit as key and list of all cellIndex having that digit.
  • 22.
    Class • Sudoku isabstract base class • It has abstract methods – Solve – Load • ClassicSudoku is concreate class for 9 x 9 Classical Sudoku • ClassicSudoku class has specific static variables –size = 9 –invert = 1022 etc.
  • 23.
    Class • ClassicSudoku classhas specific static methods – GetRowIndex – GetColumnIndex – GetBlockIndex • These method takes cellIndex as input parameter and return index for specific region
  • 24.
    Algorithm Methods • Eachalgorithm is implemented as function Solve<Algorithm Name> • Most of the algorithms has helper function to work on given region with name <Algorithm Name>SolveARegion
  • 25.
    Future Scope • Theabstract base class Sudoku can be extended for different size of Sudoku puzzles – Mini Sudoku for kids 4 x 4 – Super Sudoku 12 x 12 – Giant Sudoku 15 x 15 – Monster Sudoku 25 x 25 • The GetBlockIndex method can be modified to support Irregular Sudoku
  • 26.
    Future Scope • Theabstract base class Sudoku can be extended for different types of Sudoku puzzles – Trio Sudoku – Odd-Even Sudoku – Consecutive Sudoku – Diagonal Sudoku – Irregular Sudoku – Kakurofied Sudoku etc.
  • 27.
    Agenda • Why name: “Digi-Sudoku” ? • Overall Architecture • Finite State Machine • Use Cases and Execution Flow • Naming Convention • References • Questions - Answers
  • 28.
    Reference • Book :“A to Z of Sudoku. Science behind Sudoku” – by Narendra Jussien – ISBN: 8130908573 – ISBN13: 9788130908571
  • 29.
    Reference • Book :“Times Book of Gen-X Sudoku” – https://www.amazon.in/Times-Gen-X-Sudoku- Mohanlal-Naresh/dp/8189906046 – ISBN-10: 8189906046 – ISBN-13: 978-8189906047
  • 30.
    Reference • CSS Stylefrom github <style type="text/css"> table { margin:1em auto; } td { height:30px; width:30px; border:1px solid; text-align:center; } td:first-child { border-left:solid; } td:nth-child(3n) { border-right:solid ; } tr:first-child { border-top:solid; } tr:nth-child(3n) td { border-bottom:solid ; } </style>
  • 31.
    Agenda • Why name: “Digi-Sudoku” ? • Overall Architecture • Finite State Machine • Use Cases and Execution Flow • Naming Convention • References • Questions - Answers
  • 32.
  • 33.