


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!



“There are 10 different kinds of people in the world: those who know binary and those who don’t.”
This MP is intended to give you a chance to acquaint yourself (or reacquaint yourself) with the bit-wise logical operators and iteration in a higher level language, before we introduce these concepts in MIPS. It will also give you a chance to familiarize yourself with a chunk of C code that we will be implementing in MIPS in later MPs.
In this MP, you will be programming in C. If you are already familiar with C and bitwise operations in C, feel free to skip this section.
Use the following command to compile bits.c. It will produce an executable called ”bits”. The compiler will output any warnings that occur during compilation. Although it is not necessary to turn in a code that compiles with no warnings, you may wish to eliminate all of them, as they may be indicative of bugs.
g++ -Wall -o sudoku sudoku.c
In this MP, you will be dealing with bit arrays. In Java, one way to implement a bit array would be to simply declare a boolean array. Since C has no built-in boolean type, this option is not available to us. It is possible to just use an integer to store a bit, and then use an array of integers. However, we are going to view an integer as being a length 32 bit array. So, the nth bit in the array will be the nth bit of the integer. If we need a bit array longer than 32 bits, we can declare an array of integers, and then the first integer stores bits 0 through 31, the second integer stores bits 32 through 63, and so on.
Some useful operators:
- the right shift operator. Unlike the Java version, the C >> operator will either do >> (signed right shift) or >>> (unsigned right shift). Which one it does is dependent on the architecture and datatype being right shifted. When right shifting a value with the highest bit set, it would be a good idea not to make any sort of assumptions about whether a 0 or 1 is used to fill in the high bits.
In this MP, you will complete a program that solves Sudoku puzzles; if you do not know what Sudoku is, please Google it now and then continue reading this assignment. The program uses bit-masks to represent the possible states for each square of the Sudoku puzzle. As each square can be any one of 9 numbers (1-9), we will use 9 bits (bits 0-8, where bit 0 is the least significant bit (LSB)) to represent which of the numbers each square can be. For example, if the value stored for a square is 0x14f where bits 0, 1, 2, 3, 6, and 8 are set, then this square can be the values 1, 2, 3, 4, 7, and 9 and not the values 5, 6, and 8. The key to solving Sudoku puzzles is eliminating possibilities for an unknown square until there is only one remaining possibility which must be the answer. We use to rules to eliminate possibilities:
if isum is not all possibilities: set board[i][j] to possibility not in isum changed = true
jsum = UNION of board[i][k] for k in 1 to 9, where k != j if jsum is not all possibilities: set board[i][j] to possibility not in jsum changed = true
ksum = UNION of board[x][y] for each square in 3x3 square not including (i,j) if ksum is not all possibilities: set board[i][j] to possibility not in ksum changed = true endfor endfor
Note: This is a challenging problem.
We strongly encourage you to test your code. We’ve provided some simple test case; you are encouraged to develop your own as well.
Hand in your code by using the handin program on any EWS Linux machine. The command to submit MP1 is:
handin -s mp
You will need to submit a sudoku.c and a partners.txt containing the netids of everyone in your group, one per line. Make sure these files are in the directory you run handin from. You may work alone, or in a group of up to three people. Each group should submit the MP through a single account. You can check the status of your submission by typing:
handin -i mp