0% found this document useful (0 votes)
264 views3 pages

Sudoku

This document discusses algorithms for generating Sudoku puzzles of varying difficulty levels with unique solutions. It presents a mathematical model using a 3D matrix of binary variables to represent a Sudoku puzzle. Constraints are defined to ensure each row, column and 3x3 box contains the digits 1-9 uniquely. An algorithm uses depth-first search to solve puzzles and ensure unique solutions. The time complexity of generating puzzles is analyzed, showing the creation of starting patterns takes constant time while checking uniqueness using depth-first search is O(V+E). Examples of generated Sudoku puzzles are provided. The document concludes Sudoku is an interesting mathematical game that has grown popular in recent decades.

Uploaded by

Pero Kvržica
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
264 views3 pages

Sudoku

This document discusses algorithms for generating Sudoku puzzles of varying difficulty levels with unique solutions. It presents a mathematical model using a 3D matrix of binary variables to represent a Sudoku puzzle. Constraints are defined to ensure each row, column and 3x3 box contains the digits 1-9 uniquely. An algorithm uses depth-first search to solve puzzles and ensure unique solutions. The time complexity of generating puzzles is analyzed, showing the creation of starting patterns takes constant time while checking uniqueness using depth-first search is O(V+E). Examples of generated Sudoku puzzles are provided. The document concludes Sudoku is an interesting mathematical game that has grown popular in recent decades.

Uploaded by

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

2

Sanjay Jain et al.: Mathematical and C Programming Approach for Sudoku Game

number is multiplied by the number of equivalent


configurations to a full grid, totaled up and multiplied by
1881169920 ( 9!x72x72 ) for the total number of valid
Sudoku grids; as in[8],[9],[10].
Sudoku most commonly appears in its 9x9 matrix form.
The rules are simple: fill in the matrix so that every row,
column, and 3x3 sub matrix contains the digits 1 through
9 exactly once. Each puzzle appears with a certain number
of givens. The number and location of these determines
the games level of difficulty. Figure 1 is an example of a
9x9 Sudoku puzzle. This puzzle idea can accommodate
games of other sizes. Of course, a 4x4 puzzle would be
easier and a 16x16 puzzle, harder. In general, any n x n
2
game can be created, where n=m and m is any positive
integer. In fact, the 25 x 25 puzzle is sometimes called
Samurai Sudoku, because it is much more challenging and
time -consuming. And there are numerous other variants of
the game; as in[15].

2. Problem Analysis
Since Sudoku game is hugely attractive for worldwide
players in different intellectual levels, it is significantly
necessary for researchers to create puzzles tailored to the
difficulty requests of players in a tolerable time.
Meanwhile, these created puzzles must yield a unique
solution so that players can complete the puzzles based on
confirm ed cells using logic-deducing step by step. A puzzle
with unique solution also shows sufficient intellectual
challenges in the pursuit of terminal answer, and highlights
the inherent charm of Sudoku game.
Thus, we develop a program to construct specific Su doku
puzzles with the consideration of the following three
requirements: as in[2].
2.1. Varying Difficulty
Essentially, the program should be able to create puzzles
in different levels of difficulty. It regulates that the program
for creating must be designed by means of two jobs as
follows:
Difficulty level: define what the difficulty level is, and
evaluate a fixed Sudoku puzzle by a grading program.
Extensibility: A varying number as a metric of
difficulty request from a play can be input by the player.
Based on this number, the algorithm for creating must be
applicable to generate diverse puzzles satisfying the
difficulty request of the player.
2.2. Unique Solution
All generated Sudoku puzzles must be guaranteed to
yield a unique solution by a solving algorithm.
2.3. Minimizing Complexity
The programs of all these algorithms must finish their
jobs in a short time accepted by users or players.

2.4. Assumptions
We scale the game environment of a Sudoku puzzle
within a 9 -by-9 grid, and take no consideration of the
Sudoku puzzle in other size of the grid.
All the statistic data of the running time in this paper
are counted by our computer. These data have reliable
statistic values and comparability since they are collected
under the same computational condition.
2.5. Computational complexity of the Sudoku Problem
The computational complexity for a Sudoku problem is
analytically valuable, in fact, at every step there is always a
cell that can be filled only with a number, than the
complexity results O(n^2),where n is the number of cells for
each row or column,(in our case n=9).
Instead, for a generalized Sudoku problem (a Sudoku
problem that has not a uniqu e solution) the computational
complexity is not easily valuable analytically but may be
evaluated by comparison with the corresponding one of a
problem, the mathematical complexity of which has been
evaluated and is known; as in[3],[4] .

3. Mathematical Model to Describe


Sudoku
3.1. Variables in the Mathematical Models
To describe a mathematical model first of all variables
and their kind (for example binary, integer.) should be
defined.
In this model a 3D matrix 9x9x9 of variables is defined,
with a total amount of 729 elements. Each so defined
variable is binary and characterized by three indexes: i , j ,
k: the index i and j define respectively the row and the
column of a generic position in a Sudoku schema; the index
k represents integer in the range 1 to 9 which may be present
in a generic position. Being the variables binary they can
assume only the values 0 or 1: 0 value is assumed if in the
position i, j, the k integer is not included and the value 1
if the position i,j is filled with the k integer.
3.2. The Objective Function
In this point an objective function to be minimized or
maximized should be define d. But one must remark that in
our case one need to determine only an admissible solution,
because every Sudoku schema has one and only one
solution: then the admissible solution is automatically the
optimal one.
As a consequence the value of objective function is out
from our interest and a generic constant value may be
assumed like objective function, for instance the unit
value.
3.3. Constraints
The constraints, necessary to limit the field of the

Sanjay Jain et al.: Mathematical and C Programming Approach for Sudoku Game

return 0;
}
This program gives in output a generalized Sudoku
instance, but we cannot be sure that this instance has a unique
solution.
5.1. Comparison with Existing One
To generate an instance with unique solution the
following method, developed by Professor Della Croce and
professor Ferro of Politecnico di Torino is used.
Suppose that the model presented above has been solved
and a feasible solution has been found. Denote by SOL(i,j)
the value of the element (i,j) of the schema in the feasible
solution. Solve the following model P2:
Variables: Xi,j,k binary i=1...9, j=1...9, k=1...9
Objective Function: min

z = i , j ,k : SOL (i , j )=k Xijk

Constraints:

i X i, j ,k =1j, k { stands "For All"


j Xi, j, k = 1i, k
j Xi, j, k = 1i, j
i j Xi, j, k =1 k ; i [1,3] j [1,3]
i j Xi, j, k =1 k ; i [1,3] j [ 4, 6]
i j Xi, j, k =1 k ; i [1,3] j [7,9]
i j Xi, j, k =1 k ; i [ 4, 6] j [1,3]
i j Xi, j, k =1 k ; i [ 4, 6] j [ 4, 6]
i j Xi, j, k =1 k ; i [ 4, 6] j [7,9]
i j Xi, j, k =1 k ; i [7,9] j [1,3]
i j Xi, j, k =1 k ; i [7,9] j [ 4, 6]
i j Xi, j, k =1 k ; i [7,9] j [7,9]
The solution of this model provides a feasible solution
also to the previous model. The objective function of model
P2 minimizes the sum of the elements in the grid having the
same value obtained in the solution of the previous model.
Hence, as each grid is composed by 81 elements, if the
objective function value of model P2 is equal to 81 (Z=81),
then the Sudoku problem has unique solution, else it has not.
5.2. Solving Algorithm: Depth-first Search
An effective solving algorithm for searching out all the
feasible solutions of a Sudoku puzzle is indispensible for
the generating algorithm to judge whether a created puzzle
ha s a unique solution. Since a Sudoku puzzle is shown as a

9 -by-9 grid with sufficient information from givens and


strict constraints of game rules, it is feasible to search out
all the solutions of the puzzle using enumerating search.
For finding out a solution as a terminal pattern or judging
whether a created puzzle is unique-solvable, we build a
Sudoku solver by the mechanism of Depth -first search.
The solver searches empty cells from left to right, top to
bottom in the grid. It attempts to fill a potential 1-through-9
digit in each empty cell while satisfies the three constraints
of game rules. Once none of digits from 1 through 9 can be
filled in an empty cell to meet the constraints, the solver
backtracks to the previous empt y cell and substitutes the
filled digit there into another untried potential digit. In this
way the solver continuously performs the search until all
the potential solutions are searched out and recorded.

6. Results
Based on the specification of algorithms above, we
create Sudoku puzzles in different levels respectively
within tolerable time using our developed solving and
generating algorithms while guarantees each of these
puzzles has a unique feasible solution.
Our algorithm finds at least one feasible solution, if it
exists. Originally, we assumed each Sudoku puzzle has one
unique solution since usually an answer is provided with
each puzzle. However, after playing a few games, we
discovered that uniqueness is not a requirement for puzzle
creators. Some puzzles have multiple solutions. In such
cases, our solution was correct but distinct from the solution
provided by the puzzle creators.

7. Analysis of Algorithm Complexity


For generating Sudoku puzzles we develop an algorithm
with negligible space co mplexity. Thus we concern
significantly about time complexity of our algorithm, and
focus on reducing it in order to achieve the generation of
Sudoku puzzle within tolerable time for players.
The entire algorithm for generating Sudoku puzzle is
divided into two parts: to create a terminal pattern and then
to dig holes on it. The time complexity of creating a
terminal pattern proves to be O(1) , which indicates that a
terminal pattern can be produced within constantmagnitude time. In the algorithm of generating puzzles, the
program does trials of digging a hole at most 81 times in
the terminal pattern. For the uniqueness feasible solution
derived from the constructed puzzle, a solver built by the
Depth-First Search is called to find out all potential
solutions of the dug-out puzzle once a trial of digging a
hole is done at an unexplored cell. The time complexity of
the Depth -First Search proves to be (V + E) as in[14].
The amount of (V + E) in the problem of solving a Sudoku
puzzle is estimated to be less than 1500000.

Journal of Game Theory 2014, 3(1): 1-6

8. Examples
In this paper some examples of Sudoku instance on
which our model has been tested will be given.
Example of Sudoku and its solution.

9. Conclusions and Future


Developments
The Sudoku mathematical game, born about two
centuries ago, but largely spread in World only during the
last years, has been studied and analysed in details.
Our model is very efficient, because it is able to solve
every Sudoku instance in a very short time; it takes 0.2
seconds to 0.5 seconds for the diabolic ones according to
their difficulty levels. This fact shows that the different
difficulty between two levels affects the performance of a
human solver but not that of the program.
A mathematical model has been formulated. In addition,
the mathematical model has been implemented in a
computer solver and in parallel a program has been
developed able to generate Sudoku games. Some
applications of this analytical and numerical work have
been presented too.
Further developments in this field should consider the
uniqueness of solution in r elation to the minimum number
of input data necessary for this condition.
Another example with their solution is

ACKNOWLEDGEMENTS
The authors are thankful to the reviewers for their
suggestions to improve the present paper.

REFERENCES
[1] Bertram Felgenhauer & Frazer Jarvis, 2006. Mathematics of
Sudoku I. Mathematical Spectrum 39 (2006): 15-22.
[2]

Wei-Meng Lee, Programming Sudoku (Technology in


Action), Apress. 2006.

[3]

F. Della Croce, G. Ferro, I love Sudoku, Mondatori, Torino,


2006.

[4]

R. Tadei, F. Della Croce, Ricerca operativa e ottimizzazione,


Progetto Leonardo, Esculapio, Bologna, 2002.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy