Daa (PBL) New3
Daa (PBL) New3
Daa (PBL) New3
PBLReport
on
Sudoku Solver
Submitted By:
Khushi Pachauri
BTech/CSIT(5-B)
2100290110077
INDEX
1. Problem Statement
2. Algorithm
3. Program with Output
4. Scope
5. Extension Declaration
6. Conclusion
PROBLEM STATEMENT
Solving Sudoku has been a challenging problem in the last decade. The purpose has been to
develop a more effective algorithm in order to reduce the computing time and utilize lower
memory space. This essay develops an algorithm for solving Sudoku puzzle by using a method,
called pencil-and-paper algorithm. This algorithm resembles human methods, it describes how
a person tries to solve the puzzle by using certain techniques. Our ambition is to implement the
There are currently different variants of Sudoku such as 4X4 grids, 9X9 grids and 16X16 grids.
This work is focused on classic and regular Sudoku of 9X9 board, and then a comparison is
performed between the paper-and-pencil method and the Brute force algorithm. Hopefully, by
doing this work we might be able to answer the following questions: How does the pencil-
andpaper algorithm differ from the Brute force algorithm? Which one of them is more
effective?
Back Tracking
The unique missing method and the naked single method are able to solve all puzzles with easy
and medium levels of difficulty. In order to solve puzzles with even more difficult levels such
as hard and evil the backtracking method has been used to complete the algorithm. A human
player solves the puzzle by using simple techniques. If the puzzle is not solvable by using the
techniques the player then tries to fill the rest of the empty squares by guessing.
The backtracking method, which is similar to the human strategy (guessing), is used as a help
method to the pencil-and-paper algorithm. In other words, if the puzzle cannot be filled when
using the unique missing method and the naked single method, the backtracking method will
take the puzzle and fill the rest of the empty squares. Generally, the backtracking method finds
an empty square and assigns the lowest valid number in the square once the content of other
squares in the same row, column and box are considered. However, if none of the numbers from
1 to 9 are valid in a certain square, the algorithm backtracks to the previous square, which was
filled recently.
The above-mentioned methods are an appropriate combination to solve any Sudoku puzzles.
The naked single method can find quickly single candidates for the empty squares that need
only one single value. Since the puzzle comes to its end solution the unique missing method
can be used to fill the rest of the puzzles. Finally, if either method fills the board the algorithm
board = [
[7,8,0,4,0,0,1,2,0],
[6,0,0,0,7,5,0,0,9],
[0,0,0,6,0,1,0,7,8],
[0,0,7,0,4,0,2,6,0],
[0,0,1,0,5,0,9,3,0],
[9,0.4,0,6,0,0,0,5],
[0,7,0,3,0,0,0,1,2],
[1,2,0,0,0,7,4,0,01,
[0,4.9.2,0,6,0,0,7] def
solve(bo):
find = find_empty(bo)
True clse:
range(1,10): if valid(bo,
i, (row, col)):
bo[row][col] =1 if
bo[row][col] = 0 return
for i in
range(len(bo[0])): if
bo[pos[0]][i] == num
and pos[1] != i:
return False
# Check column
GULPY
board =
[7,8,0,4,0,0,1,2,0],
[6,0,0,0,7,5,0,0,9],
[0,0,0,6,0,1,0,7,8],
[0,0,7,0,4,0,2,6,0],
[0,0,1,0,5,0,9,3,0],
[9,0,4,0,6,0,0,0, 5],
[0,7,0,3,0,0,0,1,2],
[1,2,0,0,0,7,4,0,0],
[0,4,9,2,0,6,0,0,7]
self.model = None
update_model(self):
self.cubes[row][col].set(val) self.update_model() if
sell.cubes[row][col].set_temp(0)
self.update_model() return
(int(y),int(x)) clse:
is_finished(self): for i in
range(self.rows): for j in
range(self.cols):
if self.cubes[i][j].value == 0:
height):
self.width = width
self.selected = False
self.value == 0:
0):
event.key == pygame.K_4:
key = 4 if event.key ==
pygame.K_35:
pygame .K_6:
pygame K_7:
key=7
if event key == pygame.K_8:
event.key = pygame.K_DELETE:
i, j = board selected if
board.cubes[i][j].temp != 0: if
board.place(board.cubes[i][j].temp):
print("Wrong")
strikes += 1 key =
None if
board.is_finished():
print("Game over")
run = False
pos = pygame.mouse.get_pos()
clicked = board.click(pos) if
clicked: board.select(clicked[0],
main() pygame.quit()
OUTPUT SCREENSHOTS
SCOPE
Sudoku is a logic-based puzzle that is played by numbers from 1 to 9. The Puzzle first appeared
in newspapers in November 1892 in France and then Howard Garns an American architect
presented it in its modern form [1,5]. There are already many journals, papers and essays that
researched Sudoku Solvers and most of them present different types of algorithms. Sudoku’s
popularity is based on several reasons. First of all, it is fun and fascinating, and very easy to
learn because of its simple rules. There are currently many different types of Sudoku puzzles,
classic Sudoku that contains a 9X9 grid with given clues in various places, and mini Sudoku
that consists of a grid with 4X4 or 6X6 sizes. The other type of Sudoku is Mega Sudoku which
contains a grid with 12X12 or 16X16 sizes [2]. In this text, the focus is mostly on the classic
Sudoku, i.e. 9X9 grid. Furthermore, Sudoku has become so popular, compared to other games,
all over the world because its rules are easy to understand it can improve our brain and also it
is fun.
Extension Declaration
Further research needs to be carried out in order to optimize the pencil-and-paper algorithm. A
possible way could be implementing of other human strategies (x-wings, swordfish, etc.). Other
and also make sure that these strategies can solve any puzzles with any level of difficulties.
CONCLUSION
This study has shown that the pencil-and-paper 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 back tracking algorithm. The proposed algorithm is able to solve such
puzzles with any level of difficulties in a short period of time (less than one second). The testing
results have revealed that the performance of the pencil-and-paper algorithm is better than the
back tracking algorithm with respect to the computing time to solve any puzzle.
The back tracking algorithm seems to be a useful method to solve any Sudoku puzzles and it
can guarantee to find at least one solution. However, this algorithm is not efficient because the
level of difficulties is irrelevant to the algorithm. In other words, the algorithm does not adopt
ntelligent 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. As it has already stated the main advantage of using the algorithm is the