CS127 Final Project

Due 5:00PM Monday, 3/15/04.

You may talk to other people about your project, and you may help one another, but you should write and hand in your own program. If you get significant help from someone or borrow a small piece of code, acknowledge that help in both your documentation and in comments in the code itself.

What to hand in

By 5:00 Monday, March 15, submitted via HSP.

Project Option #1: Changelings

In the crossword puzzle books I buy, there is a kind of word puzzle called a Changeling. A changeling (in this context, anyway) is a pair of words with the same number of letters. To solve the changeling, you show a sequence of words, each differing from the previous word by a single letter, that transforms the first word of the changeling into the second.

For example, one solution to the changeling "CAT to DOG" is "CAT, COT, DOT, DOG." The intermediate words must, of course, be words (and in fact, my crossword books say "words beginning with a capital letter, slang, obsolete words, and contractions are not allowed"). Note that in this example, we have the smallest possible number of words, since CAT and DOG differ in three letter positions, and there are three letter transitions in this solution. In a contest of changeling solutions, short solutions win. (Actually, short and clever solutions would be better than the short and dull solutions that are most common, but I won't ask you to write a program to judge cleverness.)

For this project, you will write a program that uses a dictionary to compute solutions to changelings.

To make your changeling programs uniform (so it's easy for me to test them all in the same way), I want you to implement the following command-line interface. The user should be able to run your program in one of two ways. First,


java Changeling dictionaryfile firstword secondword

should compute a solution to the changeling starting at firstword and going to secondword using the indicated dictionary file. Second,


java Changeling dictionaryfile changelingfile

should compute solutions to the changeling word pairs that appear, one space-delimited pair per line, in changelingfile. If the user runs the program with some number of command-line arguments other than two or three, the program should print an appropriate usage message and exit.

So, how are you going to compute changeling solutions? There are undoubtedly many ways to solve this problem, but here is the way I want you to do it. Build a graph out of the dictionary file where each word is a vertex of the graph and two words/vertices are connected if they are the same length and differ by only one letter. Then use a breadth-first search starting at the first word until you find the second word. Then print out the path, if any, that you discovered in this way.

Building the graph can be done more efficiently than by comparing every pair of words (an Omega(N^2) process that would take quite a long time on an 80,000-word dictionary). How to do so is part of what you need to figure out.

Think about this problem before running to the computer to start coding. It's not easy, but the program should be lots of fun to play with when you're done.

Project Option #2: Spreadsheet

When you enter a formula into a spreadsheet, you typically cause the value of one cell in the spreadsheet to depend on the values in one or more other cells. For example, if you enter "=A1 + B1" into cell C1 (using a common cell-naming and formula-constructing scheme), you cause C1 to depend on both A1 and B1. If you then went on to enter "=A1 + C1" into B1, you would have a problem. C1 would now depend on B1, which in turn depends on C1. The spreadsheet would be forced to report an error. (Alternatively, the spreadsheet could loop infinitely, but that would probably reduce its utility.) When I try this using Microsoft Excel, I end up with a big error dialog, followed by some weird blue arrows connecting B1 and C1 to show me the circular references.

For this project, you will write a rudimentary spreadsheet program. This program should allow you to do the following:

In response, the program should:

The file format for the stored spreadsheets should look like this:


A1:5
A2:37
B2:=A1+A2
A3:=A2+B2

That is, each line of the file will represent a single cell, with the cell's column and row (A and 1, for example) followed by a colon, followed by the number or formula in the cell.

You may design either a text-based user interface or a graphical user interface. That part of the program is not easy to design, but you can certainly take hints from existing spreadsheet software.

To compute formula values and to detect circular references, you should build a dependency graph out of the cells. That is, let all non-empty cells be vertices in the graph. There is a directed edge from cell V to cell W if W contains a formula that refers to cell V. That is, arrows point towards the dependent cell. Once you have this graph, you can sort the graph topologically to determine the order in which you should compute values, as well as to detect circular references.

Grading Criteria

Advice





Jeff Ondich, Department of Mathematics and Computer Science, Carleton College, Northfield, MN 55057, (507) 646-4364, jondich@carleton.edu