

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


University of California, San Diego Dept. of Computer Science and Engineering CSE 30 โ Computer Organization and Systems Programming Programming Assignment #3 โ Sudoku Solver
Sudoku is a logic-based number-placement puzzle. The objective is to fill a 9ร9 grid so that each column, each row, and each of the nine 3ร3 boxes (also called blocks or regions) contain the digits from 1 to 9 only one time each. The puzzle setter provides a partially completed grid.
Consider the puzzle below and its solution:
The initial board is represented as a one-dimensional array of 81 integers as shown below.
The entries โ0โ denote empty spaces. The first element is row 0, column 0; the second
element is row 0, col 1, etc. To access the data at (row, col), use the following notation: board[row * width + col];
const int width = 9; const int board[] = { 7, 9, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 6, 9, 0, 0, 8, 0, 0, 0, 3, 0, 0, 7, 6, 0, 0, 0, 0, 0, 5, 0, 0, 2, 0, 0, 5, 4, 1, 8, 7, 0, 0, 4, 0, 0, 7, 0, 0, 0, 0, 0, 6, 1, 0, 0, 9, 0, 0, 0, 8, 0, 0, 2, 3, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 5, 4 };
Your assignment is to create a solver for โeasyโ Sudoku puzzles, i.e., ones that you do not have to โguessโ then backtrack to solve. Your program should output the final results as follows:
7, 9, 6, 8, 5, 4, 3, 2, 1 2, 4, 3, 1, 7, 6, 9, 8, 58, 5, 1, 2, 3, 9, 4, 7, 61, 3, 7, 9, 6, 5, 8, 4, 29, 2, 5, 4, 1, 8, 7, 6, 34, 6, 8, 7, 2, 3, 5, 1, 9 6, 1, 4, 5, 9, 7, 2, 3, 85, 8, 2, 3, 4, 1, 6, 9, 73, 7, 9, 6, 8, 2, 1, 5, 4
You can find skeleton code for the project at: http://mesl.ucsd.edu/gupta/cse30/sudoku.c
Hints and General Comments:
START EARLY!
As with any programming project, it is important that you work incrementally and test your code often. You should start your program by creating a function that will output the board data in the required format.
You will not be able to finish this the night before. It is unlikely that you will be able to complete this even if you start a few days before the due date.
This is worth 20% of your grade
and will help you with debugging later.
Your project will be graded by changing the input array and checking the corresponding output. There are countless examples of Sudoku puzzles on the Internet. You should test your program with more than just this sample puzzle.
It is a good idea to first think out the algorithm for your solution. For example, write a pseudo code solution first (or use another programming language that you are familiar with) to test and debug your ideas. Then carefully write and test the C code.
Obligatory cheating statement: There are undoubtedly many solutions for this in many languages floating around on the web. Remember that you are responsible for understanding every line of code that you have written. If you cannot explain to someone, on the spot, what every piece of your code does, then that is considered cheating (this is another reason why it is important to comment your code โ so that you can remember what you have written at a later date). It is OK to talk with others in the class about your ideas for algorithms. It is not OK to share code. You should write every line of code yourself. Finally, your code will be compared with others using software, which also include any solutions that may be on the Internet as well as solutions from previous years.