CSE 303: Autumn 2006, Assignment 3

Due: Wednesday 25 October 2006, 2:00pm

Updates

Assignment Overview

This is an individual assignment in which you will modify some small C programs. Begin by downloading hw3.tgz and unpacking it with tar -xvzf hw3.tgz. This contains all the files referred to in this assignment. (Note: Soon we will assume that you know how to unpack files like this.)

1. Sudoku

The program sudoku.c solves sudoku puzzles. As explained in this Wikipedia article on sudoku, the aim of these puzzles is to enter the digits 1 through 9 in each cell of a 9×9 grid made up of 3×3 subgrids (called "regions") so that each row, column, and region contains exactly one instance of each digit. A set of clues, or "givens", constrain the puzzle such that there is only one way to correctly fill in the remainder.

Description

The given program attempts to solve puzzles passed in on stdin. The expected format can be seen in puz9x9a.txt. Cells that contain the digits 1-9 are clues, and cells that contain 0 must be filled in by the program. If you name the program sudoku when you compile it, you should be able to invoke it by typing ./sudoku <puz9x9a.txt. The result is printed on stdout, along with a header showing the date. The output should look exactly like puz9x9asolution.txt, though the date will vary.

Changes

You will fix some problems with this program, and then modify it.

Advice

Understand the code provided to you. You can use man to learn about C library functions that are unfamiliar (e.g. man puts). Some functions (such as time), are also Linux commands, and man may show documentation for these rather than the C library functions. The documentation is there, however, under a different "section". You can use man -a to show all man pages for all sections one after the other, or you can use man -S <section name>, to access the section you want. The section name is given is given in parentheses after the page name in the first and last lines of the man page (e.g. man -S 2 time).

When debugging the segmentation fault, try adding printf statements to the program to find out where the program crashes. (Sometimes, this is the only way to debug such problems.) Make sure you remove these printf statements in your final version.

When detecting bad input, you don't need to detect every possible deviation from the format we specified (although you are free to do so, if you wish). We only require you to detect format errors that would cause you to read incorrect values from the file.

Note: Writing programs like this one to solve puzzles is a classic problem in artificial intelligence. This program searches the entire space of solutions, which is horribly inefficient and won't produce an answer in any reasonable ammount of time for some puzzles. We invite you to look for better solutions outside of class!

2. Bounding Boxes

You have been hired to help develop a high-performance 2D graphics system for a handheld device. Your current task is to develop a "bounding box" data structure that will be used throughout the system, and you will experiment with a number of options. Open the file bboxes.c, which contains the definition for a BBox type, and several supporting functions. At the location indicated, you will add four functions that compute the "union" of two bounding boxes. The union of two bounding boxes is a new bounding box that is just large enough to enclose the two original bounding boxes. Note that, as in most window systems, X increases from left to right, and Y increases from top to bottom. It is reasonable to assume that top <= bottom and left <= right.

Advice

You can comment out parts of BBoxTest to test some of your functions before you write the others. No function body needs to be longer than a few lines. The correct output is below.

[(0,0) (0,0)]
[(-4,-8) (0,0)]
[(0,0) (5,10)]
[(-3,-3) (1,1)]
[(-1,-1) (6,6)]
[(-4,-8) (0,0)]
[(-4,-8) (5,10)]
[(-3,-3) (6,6)]
[(-4,-8) (0,0)]
[(-4,-8) (5,10)]
[(-3,-3) (6,6)]
[(-4,-8) (0,0)]
[(-4,-8) (5,10)]
[(-3,-3) (6,6)]
[(-4,-8) (0,0)]
[(-4,-8) (5,10)]
[(-3,-3) (6,6)]

3. Survey

Please fill out this survey to give the CSE 303 teaching staff us a sense of how well our course materials are being received and to ask for your feedback. The survey is completely anonymous. Please fill it out only once.

4. Extra Credit

Remember the course policy on extra credit. You may do either or both of the following problems.

Assessment

Your solutions should be

Turn-in instructions

Use the standard turn-in instructiond described here. Your directory should contain the files sudoku.c, bboxes.c, and readme.txt. If you do the extra credit, you should also turn in sudoku2.c and/or bbOverlap.c.