0% found this document useful (0 votes)
137 views

OPERATING SYSTEM PROJECT REPORTw

This document appears to be a project report for developing a Sudoku solution validator program. It includes an introduction explaining the Sudoku logic puzzle and the recursive solving algorithm to be implemented. It then outlines the methodology including declaring necessary functions like finding empty cells, checking if a number can be placed in a given row/column/grid. It also includes a flow chart and code snippets from the program to validate Sudoku solutions through checking placement rules.
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)
137 views

OPERATING SYSTEM PROJECT REPORTw

This document appears to be a project report for developing a Sudoku solution validator program. It includes an introduction explaining the Sudoku logic puzzle and the recursive solving algorithm to be implemented. It then outlines the methodology including declaring necessary functions like finding empty cells, checking if a number can be placed in a given row/column/grid. It also includes a flow chart and code snippets from the program to validate Sudoku solutions through checking placement rules.
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/ 20

Sir Syed University of Engineering & Technology

Computer Engineering Department


Spring Semester 2022

Project Report File


OPERATING SYSTEMS (CE-303)

PROJECT TITLE:-
SUDOKU SOLUTION VALIDATOR

SUBMITTED BY:

WAQAS AHMED--------------- 2020-CE-127

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

5. EXPERIMENT & RESULT Page no#


9 to 18
1. Flow Chart
2. Program Code
3. Output

6. CONCLUSION Page no#


18

7. FUTURE SCOPE Page no#


19

REFERENCES Page no#


20
8.

Page 3
ABSTRACT

Sudoku is a logic-based, combinatorial number placement puzzle game.


The objective of this game is to fill a × grid with digits so that every
row, column and inner box is filled with number from 1 to without
duplicates. The shape of inner boxes may vary, but all must have
exactly blocks. In most situations, a Sudoku game should have a unique
solution. However, there can be cases that a Sudoku game has multiple
solutions. Usually a game with multiple solution is considered to be
more difficult than the one that has a unique solution. Sudoku was
originated in the late 16th century. La France developed the embryonic
form of the modern Sudoku of 9 by 9 grid with 9 3 × 3 inner boxes, and
later, it was believed that the modern Sudoku was mostly designed
anonymously by Howard Garns in 1979. However, this game became
a worldwide phenomenon not until Nikoli introduced it to Japan in
1984 and named it as . The name was later abbreviated to (Sudoku) by
Maki Kaji. Sudoku is a trademark in Japan and the puzzle is generally
referred to as Number Place, or NumPla in short. Variants Though the
9 × 9 grid with 3 × 3 inner boxes is by far the most common Sudoku
game, many other variants exist. .

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.

First, we need a solvable puzzle. Ideally, one that you can


solve by hand in order to write tests properly:

Second, we need to introduce vocabulary and rules:

Row — an array of 9 elements of the puzzle located


horizontally. (E.g. first row is [1,7,4,0,9,0,6,0,0]).

Column — an array of 9 elements of the puzzle located


vertically.
(E.g. first column is [1,0,5,0,8,3,2,0,0])

Square — an array of 9 elements of the puzzle located in


shape of 3x3 square stating from first row and column.
(E.g. first square is [1,7,4,0,0,0,5,3,0])

According to rules of traditional Sudoku: element in row |


column | square should be unique.

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

Current implementation will explore every branch until

(a) finds a solution or

(b) finds that there is no solutions. Every empty cell is a node, every
guess is the branch.

First, declare functions:

Each function will return 1 as `success` and 0 as `failure` signal.

Next, implement find_empty_cell :

In order to use it we need to declare two variables in caller-function.


This function will use pointers to this variables and modify them.

Now, implement valid function:

And now, solve function:

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

SOURCE CODE typedef struct {


int row;
#include <stdio.h>
int column;
#include <stdlib.h>
} parameters;
#include <unistd.h>
#include <pthread.h>
// Sudoku puzzle to be solved
#define num_threads 27
int sudoku[9][9];

/*
// 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

SOURCE CODE scanf("%d", &arrival_time[i]);

#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.

Sudoku solving using patterns surely lowers the execution time


required to solve huge number of Sudokus. The graphs and tables
presented in this project effectively prove the same.

Page 18
FUTURE SCOPE

The motive of this project was to review the performance of a Depth


First Search based Sudoku Solver using pattern matching. This review
used limited number of patterns that were comparatively easier to
detect than some complex patterns. However, detecting more patterns
may give considerably better results.

Future scope of project The objectives of the proposed Project is to


increase the Thinking Capability. The Game having all the records
which u perform in playing you can Select Easy, hard level according
to your choice. You can make your own Sudoku and at any Step you
can go back to One Step as well as you can see the Solution of it.

Page 19
REFERENCES

[1] http://www.sudoku-tips.com/about_sudoku.php

[2] Sato, Yuji “Solving Sudoku with Genetic Operations that

Preserve Building Blocks,” Computational Intelligence and Games

(CIG), 2010 IEEE Symposium.

[3] “JFreeChart-API” http://www.jfree.org/jfreechart/download.html

[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

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