OPERATING SYSTEM PROJECT REPORTw
OPERATING SYSTEM PROJECT REPORTw
PROJECT TITLE:-
SUDOKU SOLUTION VALIDATOR
SUBMITTED BY:
HASEEB JAVED----------------2020-CE-129
WAJAHAT AHMED----------- 2020-CE-142
FALAK SHAIR -----------------2020-CE-153
SEMESTER: 5TH
SECTION: “D”
SUBMITTED TO:
LAB TEACHER: MISS SADIA, MISS SAFINA
THEORY TEACHER: MISS HUMA
ACKNOWLEDGMENT
I would like to express my sincere gratitude to our teacher MISS SADIA for
supporting us in this project for helpful information, practical advice and
unceasing ideas that have helped us tremendously at all times in our research and
writing of this thesis. First, I wish to express my sincere gratitude to our theory
teacher MISS HUMA for her immense knowledge, profound experience and
professional expertise in Data Quality Control has enabled me to complete this
research successfully. Without his support and guidance, this project would not
have been possible. I could not have imagined having a better teacher in our study.
Haseeb Javed
Waqas Ahmed
Wajahat Ahmed
Falak shair
Page 2
NO INDEX PAGE
1. Page no# 4
ABSTRACT
2. Page no# 5
INTRODUCTION
3. Page no# 6
LITERATURE REVIEW
4. Page no#
METHODOLOGY 7 to 8
1. Algorithm
2. Implementation
Page 3
ABSTRACT
Page 4
INTRODUCTION
Sudoku programming problem is well known. There are
several algorithms that can be implemented. In this
project we’ll show one that is recursive solving (with
backtracking). This algorithm is Depth-First Search,
attempts to solve the branch completely, hence, has
exponential time complexity (O(exp(n)) and, in current
implementation, will return unsolved puzzle when
unsolvable is given.
Page 5
LITERATURE REVIEW
Sudoku was developed by an American architect, Howard Garnes, in
1979, as a numerical combinatorial puzzle. The puzzle gained
popularity in 2004, when Wayne Gould convinced The Times in
London to publish it. There are 6,670,903,752,021,072,936,960
possible combinations for completing a 9-by-9 Sudoku grid, but only
5,472,730,538 of them really count for different solutions and hence
one needs a handful of lifetimes to solve all of them. Various Sudoku
solving guides have explained the presence of a variety of patterns in
Sudoku. These patterns are mostly aimed at, and also used by, humans
to solve Sudoku by deducing hints. A machine or a processor is
expected to solve the puzzle faster by rapid guessing and backtracking,
rather than understanding every puzzle and solving it step by step. This
paper attempts to feed the tips meant for Human Sudoku solving by
detecting different patterns, to a machine and also using its power to
guess rapidly and backtrack, to gain a remarkable improvement in
Sudoku solving than a simple Backtracking approach.
Rohit Iyer, B.E (Computers), Vidyalankar Institute of Technology,
Mumbai. Amrish Jhaveri, B.E (Computers), Vidyalankar Institute of
Technology, Mumbai.
Page 6
METHODOLOGY
IMPLEMENTATION
(b) finds that there is no solutions. Every empty cell is a node, every
guess is the branch.
Page 7
ALGORITHM
DEPTH-FIRST SEARCH
PSEUDO CODE:
1. Find empty (0) cell.
1.1. If there is no empty cells -> return the puzzle.
2. Find valid guesses for empty cell.
2.1. Try to recursively solve puzzle with this guess.
2.1.1. If there is no valid guesses, then assign cell
value to empty (0) and prune this branch as dead-end.
(Backtracking)
Page 8
EXPERIMENT & RESULT
FLOW CHART
Page 9
PROGRAM CODE:
PROGRAM # 01
SOURCE CODE }
int checkcolumn(int column,int num)
#include<stdio.h>
{//This function checks whether we can put the
int sudoku[9][9];//The array which stores entries
number(num) in the column(column) of the
for the sudoku
Sudoku or not
void solvesudoku(int,int);
int row;
int checkrow(int row,int num)
for(row=0;row<9;row++)
{//This function checks whether we can put the
if(sudoku[row][column]==num)
number(num) in the row(row) of the Sudoku or
return 0;//If the number is found already present
not
at certain location we return zero
int column;
return 1;//If the number is not found anywhere
for(column=0;column<9;column++)
we return 1
if(sudoku[row][column]==num)
}
return 0 ;//If the number is found already present
int checkgrid(int row,int column,int num)
at certain location we return zero
{//This function checks whether we can put the
return 1;//If the number is not found anywhere
number(num) in the 3*3 grid or not
we return 1
Page 10
//We get the starting row and column for the 3*3 display();
grid if(sudoku[row][column]!=0)
row=(row/3)*3 ; navigate(row,column);//If the value filled at a
column=(column/3)*3; cell is not zero than it is filled with some value
int r,c; from 0 to 9 hence we move further
for(r=0;r<3;r++) else
for(c=0;c<3;c++) {
if(sudoku[row+r][column+c]==num) int ctr;//This is a counter to check numbers from
return 0;//If the number is found already present 1 to 9 whether the number can be filled in the
at certain location we return zero cell or not
return 1;//If the number is not found anywhere for(ctr=1;ctr<=9;ctr++)
we return 1 {//We check row,column and the grid
} if((checkrow(row,ctr)==1)&&(checkcolumn(col
void navigate(int row,int column) umn,ctr)==1)&&(checkgrid(row,column,ctr)==1
{//Function to move to the next cell in case we ))
have filled one cell {
if(column<8) sudoku[row][column]=ctr;
solvesudoku(row,column+1); navigate(row,column);
else }
solvesudoku(row+1,0); }
} sudoku[row][column]=0;//No valid number was
void display() found so we clean up and return to the caller.
{//The function to display the solved Sudoku }
int row,column;
printf("THE SOLVED SUDOKU \n"); }
for(row=0;row<9;row++) int main()
{ {
for(column=0;column<9;column++) int row,column;
printf("%d ",sudoku[row][column]); printf("Enter the desired sudoku and enter 0 for
printf("\n"); unknown entries\n");
} for(row=0;row<9;row++)
} for(column=0;column<9;column++)
void solvesudoku(int row,int column) scanf("%d",&sudoku[row][column]);
{ solvesudoku(0,0);//We start solving the sudoku.
if(row>8)//If the row number is greater than 8 }
than we have filled all cells hence we have
solved the sudoku
Page 11
PROGRAM # 02
/*
// Method that determines if numbers 1-9 only
Initialize the array which worker threads can
appear once in a column
update to 1 if the
void *isColumnValid(void* param) {
corresponding region of the sudoku puzzle they
// Confirm that parameters indicate a valid col
were responsible
subsection
for is valid.
parameters *params = (parameters*) param;
*/
int row = params->row;
int valid[num_threads] = {0};
int col = params->column;
if (row != 0 || col > 8) {
// Struct that stores the data to be passed to threads
Page 12
fprintf(stderr, "Invalid row or column for col int i;
subsection! row=%d, col=%d\n", row, col); for (i = 0; i < 9; i++) {
pthread_exit(NULL); // If the corresponding index for the number is set
} to 1, and the number is encountered again,
// the valid array will not be updated and the thread
// Check if numbers 1-9 only appear once in the will exit.
column int num = sudoku[row][i];
int validityArray[9] = {0}; if (num < 1 || num > 9 || validityArray[num - 1] ==
int i; 1) {
for (i = 0; i < 9; i++) { pthread_exit(NULL);
int num = sudoku[i][col]; } else {
if (num < 1 || num > 9 || validityArray[num - 1] == validityArray[num - 1] = 1;
1) { }
pthread_exit(NULL); }
} else { // If reached this point, row subsection is valid.
validityArray[num - 1] = 1; valid[9 + row] = 1;
} pthread_exit(NULL);
} }
// If reached this point, col subsection is valid. // Method that determines if numbers 1-9 only
valid[18 + col] = 1; appear once in a 3x3 subsection
pthread_exit(NULL); void *is3x3Valid(void* param) {
} // Confirm that parameters indicate a valid 3x3
subsection
// Method that determines if numbers 1-9 only parameters *params = (parameters*) param;
appear once in a row int row = params->row;
void *isRowValid(void* param) { int col = params->column;
// Confirm that parameters indicate a valid row if (row > 6 || row % 3 != 0 || col > 6 || col % 3 != 0)
subsection {
parameters *params = (parameters*) param; fprintf(stderr, "Invalid row or column for
int row = params->row; subsection! row=%d, col=%d\n", row, col);
int col = params->column; pthread_exit(NULL);
if (col != 0 || row > 8) { }
fprintf(stderr, "Invalid row or column for row int validityArray[9] = {0};
subsection! row=%d, col=%d\n", row, col); int i, j;
pthread_exit(NULL); for (i = row; i < row + 3; i++) {
} for (j = col; j < col + 3; j++) {
int num = sudoku[i][j];
// Check if numbers 1-9 only appear once in the if (num < 1 || num > 9 || validityArray[num - 1] ==
row 1) {
int validityArray[9] = {0}; pthread_exit(NULL);
Page 13
} else { columnData->row = i;
validityArray[num - 1] = 1; columnData->column = j;
} pthread_create(&threads[threadIndex++], NULL,
} isColumnValid, columnData); // column
} threads
// If reached this point, 3x3 subsection is valid. }
valid[row + col/3] = 1; // Maps the subsection to an if (j == 0) {
index in the first 8 indices of the valid array parameters *rowData = (parameters *)
pthread_exit(NULL); malloc(sizeof(parameters));
} rowData->row = i;
rowData->column = j;
int main() { pthread_create(&threads[threadIndex++], NULL,
pthread_t threads[num_threads]; isRowValid, rowData);
int row,column; // row threads
printf("Enter sudoku to check valid or not:\n"); }
for(row=0;row<9;row++) }
for(column=0;column<9;column++) }
scanf("%d",&sudoku[row][column]);
int threadIndex = 0; for (i = 0; i < num_threads; i++) {
int i,j; pthread_join(threads[i], NULL);
// Create 9 threads for 9 3x3 subsections, 9 threads // Wait for all threads to finish
for 9 columns and 9 threads for 9 rows. }
// This will end up with a total of 27 threads.
for (i = 0; i < 9; i++) { // If any of the entries in the valid array are 0, then
for (j = 0; j < 9; j++) { the sudoku solution is invalid
if (i%3 == 0 && j%3 == 0) { for (i = 0; i < num_threads; i++) {
parameters *data = (parameters *) if (valid[i] == 0) {
malloc(sizeof(parameters)); printf("Sudoku solution is invalid!\n");
data->row = i; return EXIT_SUCCESS;
data->column = j; }
pthread_create(&threads[threadIndex++], NULL, }
is3x3Valid, data); // 3x3 subsection threads printf("Sudoku solution is valid!\n");
} return EXIT_SUCCESS;
if (i == 0) { }
parameters *columnData = (parameters *)
malloc(sizeof(parameters));
Page 14
PROGRAM # 03
#include<stdio.h>
printf("Burst Time:");
int main()
scanf("%d", &burst_time[i]);
{
temp[i] = burst_time[i]; }
int i, limit, total = 0, x, counter = 0, time_quantum;
printf("\nEnter Time Quantum:");
int wait_time = 0, turnaround_time = 0,
scanf("%d", &time_quantum);
arrival_time[10], burst_time[10], temp[10];
printf("Process ID |Burst Time | Turnaround Time |
float average_wait_time, average_turnaround_time;
Waiting Time|");
printf("Enter Total Number of Processes:");
for(total = 0, i = 0; x != 0;)
scanf("%d", &limit);
{ if(temp[i] <= time_quantum && temp[i] > 0)
x = limit;
{ total = total + temp[i];
for(i = 0; i < limit; i++)
temp[i] = 0;
{
counter = 1; }
printf("\nEnter Details of Process[%d]", i + 1);
else if(temp[i] > 0)
{
printf("\nArrival Time:");
temp[i] = temp[i] - time_quantum;
total = total + time_quantum;
Page 15
} else if(arrival_time[i + 1] <= total)
if(temp[i] == 0 && counter == 1) {
{ i++; }
x--; else
printf("\nProcess[%d]\t%d\t\t%d\t\t%d", i + 1, { i = 0;
burst_time[i], total - arrival_time[i], total - }}
arrival_time[i] - burst_time[i]); average_wait_time = wait_time * 1.0 / limit;
wait_time = wait_time + total - arrival_time[i] - average_turnaround_time = turnaround_time * 1.0
burst_time[i]; / limit;
turnaround_time = turnaround_time + total - printf("\nAverage Waiting Time:%f",
arrival_time[i]; average_wait_time);
counter = 0; } printf("\nAvg Turn around Time:%f\n",
if(i == limit - 1) average_turnaround_time);
{ return 0;
i = 0; } }
OUTPUT:
PROGRAM # 01
Page 16
PROGRAM # 02
PROGRAM # 03
Page 17
PROGRAM # 04
CONCLUSION
Computer has got clear advantage over the manual system. The
computerized system is more reliable, efficient and fast at the end of
the project, I can say that computer play a very crucial role in the
development of firm. All the daily reports generated by the system are
to be checked by the concerned official so as to ensure that all the
transactions have been put through in appropriate accounts and this is
tallied with the new vouchers.
Computer does maximum work with in minimum time. Because it is
used in every field so that it provides comfort and suitability to
everyone. Providing maximum facilities and comfort to customers to
customers is main goal of the firm. To achieve this goal, other modern
facilities relating to computer should have to be provided.
Page 18
FUTURE SCOPE
Page 19
REFERENCES
[1] http://www.sudoku-tips.com/about_sudoku.php
[4]“WordPress-WebBlog”
http://attractivechaos.wordpress.com/2011/06/19/an-incomplete-
reviewof-sudoku-solver-implementations/
[5] http://www.afjarvis.staff.shef.ac.uk/sudoku/
Page 20