Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

can this be in programming language c. thanks this is the hw01.c /*___________________*/ #include #include void inputPuzzle(char puzzValues[][9], char *type, char *argv[]); void printPuzzle(char puzzValues[][9],

image text in transcribed

image text in transcribed

can this be in programming language c. thanks

this is the hw01.c /*___________________*/

#include #include void inputPuzzle(char puzzValues[][9], char *type, char *argv[]); void printPuzzle(char puzzValues[][9], char type); //These are the prototypes for the functions you will code!!! void analyzePuzzle(char puzzValues[][9], char type, char check[]); void checkRow(char puzzValues[][9], char check[], int row, int column); void checkColumn(char puzzValues[][9], char check[], int row, int column); void checkSquare(char puzzValues[][9], char check[], int row, int column); void printPossibleNums(char puzzValues[][9], char check[], int row, int column); int checkSolution(char puzzValues[][9], char check[]); int main(int argc, char *argv[]) { int solution; char puzzValues[9][9]; char type; char check[10]; //Check to make sure a puzzle file was given if (argc != 2) { printf("Command line error "); exit(-1); } inputPuzzle(puzzValues, &type, argv); printPuzzle(puzzValues, type); if (type == 1) analyzePuzzle(puzzValues, type, check); else if (type == 2) { solution = checkSolution(puzzValues, check); if (solution == 0) printf("Yes "); else if (solution == 1) printf("No "); else printf("Finish your code! "); } return 0; } /******************** inputPuzzle ************************************** void inputPuzzle(char puzzValues[][9], char *type, char *argv[]) Purpose: Reads a sudoku puzzle in from a file. Stores the values. Parameters: I char puzzValues[][] I char* type I char* argv[] Returns: Returns the type of puzzle being entered and the sudoku numbers using pointers. Notes: The puzzle file is opened and input is error checked. The lower bound is set by the puzzle type. Puzzles to be checked cannot have 0s. Puzzles to find possible solutions use 0s to indicate a blank space. Nested for loops are used to traverse the 2d array and input values. **************************************************************************/ void inputPuzzle(char puzzValues[][9], char *type, char *argv[]) { int userChoice, tmp, i, j; int lBound, uBound = 9; FILE *puzzleInput = fopen(argv[1], "r"); if (puzzleInput == NULL) { printf("Error opening the file: %s", argv[1]); exit(-1); } //Read the puzzle type fscanf(puzzleInput, "%d ", &userChoice); if (userChoice != 1 && userChoice !=2) { printf("Invalid puzzle type: %d ", userChoice); exit(-1); } *type = userChoice; if (userChoice == 1) lBound = 0; else lBound = 1; for(i=0; i uBound) { printf("Input value outside of bounds: %d", tmp); exit(-1); } else puzzValues[i][j] = tmp; } else { printf("Error reading file "); exit(-1); } } } fclose(puzzleInput); } /******************** printPuzzle ************************************** void printPuzzle(char puzzValues[][9], char type) Purpose: Prints out the two dimensional array as a sudoku table. Parameters: I char puzzValues[][] I char type Returns: n/a Notes: Nested for loops are used to traverse the two dimensional array. **************************************************************************/ void printPuzzle(char puzzValues[][9], char type) { int i, j; printf("%d ", type); for (i=0; i

this is puzzle1.txt /*----------------------*/

1 0 0 2 4 0 5 8 0 0 0 4 1 8 0 0 0 2 0 6 0 0 0 7 0 0 3 9 2 0 0 0 3 0 0 9 6 0 0 9 6 0 7 1 0 0 1 7 0 0 5 0 0 0 3 9 6 0 0 8 0 0 0 1 0 2 0 0 0 9 5 6 0 0 0 8 3 0 6 9 0 0

HW- Sudoku (high-level description): Currently you may not have learned the algorithmic strategies that you need to solve Sudoku puzzles. But you can easily 1 declare a data structure to represent a Sudoku puzzle, 2. write some functions to read Sudoku puzzle from a file, . check if a proposed solution follows the Sudoku rules (no duplicating values in a row, column, or outlined 3 x 3 square (we may discuss Sudoku rules in the class). also write a function that can list the possible values for each empty cell according to Sudoku rules 4. Instead of asking you to write a program that can solve a Sudoku puzzle, we ask you to write a program that can do some of the simple things mentioned above. Some code is already provided for the first two tasks. You will focus on the last two tasks and implement the necessary functions. HW- Sudoku (detailed description and necessary steps): The provided code hw01.c is already doing the followings: 1. Declare a minimum size data structure to store the values of a Sudoku puzzle (e.g 9x9 array of char because we will be storing numbers between 0 and 9) Read Sudoku puzzle or Sudoku solution from a file whose name is given asa command line argument . The given file would be formatted as follows: there is a number that indicates if 2. this file contains a puzzle or a solution. If the that number is 1, then this file contains a Sudoku puzzle; if that number is 2, then the file contains a Sudoku solution to be checked. The file than contains 9x9-81 values representingthe values on Sudoku puzzle or solution a) In the case of a puzzle (the first number is 1), the remaining 9x9-81 . numbers in the file will be between 0 and 9. Zero is for empty cells, 1-9 are for other cells. In the case of a solution (the first number is 2), the remaining 9x9-81 numbers in the file will be between 1 and 9. b)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Datalog Engines In Databases

Authors: Bas Ketsman ,Paraschos Koutris

1st Edition

1638280428, 978-1638280422

Students also viewed these Databases questions

Question

=+Will the guilt enhance the message?

Answered: 1 week ago

Question

Inserting Data to tables is known as DML . True / False

Answered: 1 week ago

Question

The nature and importance of the global marketplace.

Answered: 1 week ago