Answered step by step
Verified Expert Solution
Question
1 Approved Answer
******************************************************************************************************************************************* Here is the skeleton of code and if you can copy and paste it to and add on to this and finish the functions
*******************************************************************************************************************************************
Here is the skeleton of code and if you can copy and paste it to and add on to this and finish the functions at the bottom. Also if this could be in programming language C, Thanks.
*******************************************************************************************************************************************
/******************** HW01 ************************************** Author: //Your name here Purpose: Accepts a finished or unfinished sudoku puzzle and returns a correct solution check or the possible values that could be entered into every empty square. Parameters: arvg[1] name of sudoku file Returns: n/a Notes: None **************************************************************************/ #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
/*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 declare a data structure to represent a Sudoku puzzle, 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. 1. 2. 3. 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 as a 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 representing the 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. b) 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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started