Question: need help fine tuning my program here is what is should do The following program must be implemented in C programming language and it will

need help fine tuning my program

here is what is should do

The following program must be implemented in C programming language and it will be compiled and tested under Unix for grading. Problem Statement: Write a Pthreads program 'Sudoku-Checker.c' to check the validity of the proposed solution to a typical Sudoku puzzle (Refer to: https://en.wikipedia.org/wiki/Sudoku) (1) This program should be implemented by the following way: (a) The proposed solution to the given sudoku puzzle should be read from an input file. (b) One suggested strategy is to create a total of eleven separate worker threads for validating a Sudoku puzzle by ?One thread: check if each column contains the digits 1 through 9 ?One thread: check if each row contains the digits 1 through 9 ?Nine threads: check if each of the 3 3 subgrids contains the digits 1 through 9 (c) The parent thread creates the worker threads, passing each worker the location that it must check in the Sudoku grid. ?Several parameters including row and column of subgrids are required to be passed to each thread. ?Creating a data structure shown as follows is the easiest approach to implement it. ?The pointer Data will be passed to the pthread_create () function as a parameter for each separate thread to be created. (d) Each worker thread checks the validity of a particular region. Once it is done, the result must be passed back to the parent. ?Creating an array of integer values that is visible to each thread, where the ith index in this array corresponds to the ith worker thread. ?The value of an array entry set by its corresponding worker thread indicates the validity: 1 indicates valid and 0 indicates otherwise. ?When all worker threads completed, the parent thread checks each entry in the result array to determine if the Sudoku puzzle is valid.

here is the code , i can't get it to run

#include #include #include void report(char *s,int i,int j) { printf(" The sudoku is INCORRECT"); printf(" in %s. Row:%d,Column:%d",s,i+1,j+1); getch(); exit(0); } void main() { int i,j,a[9][9]; char c; int si,sj,flag; printf(" Enter the sudoku"); /* Going to read sudoku matrix (9x9). Since numbers 1 to 9 are single digit, it is enough to read them as char. To convert them from their ascii to int, subtract ascii of '0' from the character. */ for(i=0;i<9;i++) for(j=0;j<9;j++) { scanf("%c",&c); a[i][j]=c-'0'; } /*++++++++++++++++++ checking rows +++++++++++++++++++ we check each cell in each row. We start with a flag 0x0000. if 1 is found zeroth bit of flag is set. if 2 is found, first bit is set and so on. If all digits 1 to 9 are present, flag's value will be 0x01FF. If flag is 0x01FF after traversing a row, the row has all numbers 1 to 9. So, it is correct. If the flag is not 0x01FF after traversing a row, the row is incorrectly filled. Then we call report() function */ for(i=0;i<9;i++) { flag=0x0000; for(j=0;j<9;j++) flag|=1<<(a[i][j]-1); if(flag!=0x01FF) report("row",i,j-1); } /*++++++++++++++++++ checking columns +++++++++++++++++++ Just like row checking. The flag is for a column. */ for(j=0;j<9;j++) { flag=0x0000; for(i=0;i<9;i++) flag|=1<<(a[i][j]-1); if(flag!=0x01FF) report("col",i-1,j); } /*++++++++++++++++++ checking Squares (3x3) +++++++++++++++++++ Just like row checking. The flag is for a square. */ for(si=0;si<3;si++) { for(sj=0;sj<3;sj++) { flag=0x0000; for(i=0;i<3;i++) { for(j=0;j<3;j++) flag|=1<<(a[si*3+i][sj*3+j]-1); } if(flag!=0x01FF) report("square",si*3+i-1,sj*3+j-1); } } printf(" The sudoku is correct"); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!