Skip to main content.

Friday, Mar 9, 2007
Due: Wednesday, Mar 21, 2007 - 10:00PM

File Searcher

[30 points]

Complete Programming Exercise P16.8 in the textbook (page 605).

File Scrambler

[50 points]

Aoccdrnig to a rscheearch at Cmabrigde Uinervtisy, it deosn't mttaer in waht oredr the ltteers in a wrod are, the olny iprmoetnt tihng is taht the frist and lsat ltteer be at the rghit pclae. The rset can be a toatl mses and you can sitll raed it wouthit porbelm. Tihs is bcuseae the huamn mnid deos not raed ervey lteter by istlef, but the wrod as a wlohe.

In other words: According to a researcher (sic) at Cambridge University, it doesn't matter in what order the letters in a word are, the only important thing is that the first and last letter be at the right place. The rest can be a total mess and you can still read it without problem. This is because the human mind does not read every letter by itself but the word as a whole.

Well, this is actual an urban legend floating around the Internet, which you may have received in your email. Nonetheless, you are to write a program that reads in a plain text file and scrambles the words as described above -- that is, for each word that you read in from the file, keep the first and last letters in their place but mix up the order of the internal letters. The results should be written out to a different file.

Think carefully about the process that you will go through to achieve this problem -- break it down into little pieces and implement each piece as a separate method. For example, you might want to start out first writing a simple method that does the scrambling, taking a String parameter and returning a String. Once you have tested this method and made sure it works, then slowly build up the rest of the program around it to read in all the words of a file, scramble them, and write them back out.

As you are processing a file, punctuation should be kept in it's place relative to where it is in the original word. That is, if you get the next word (token) from the input file and it is the string "don't." then the "'" and the "." should stay in their respective places in the word. And in this case the first and last letter are 'd' and 't', so the only possible scramble of this word would be "dno't."

EXTRA CREDIT: File Unscrambler

[50 points]

Write a program that undoes what the previous exercise does to a file (for the most part -- in some cases there may be ambiguity in what a word should unscramble to). The way I would approach this is first to find a (dictionary) file containing a list of words from the English language on the Internet. Then read in word by word from the scrambled file and try to find a word that matches a possible unscrambling of it in the dictionary. You may need to be a little careful to make sure that your program doesn't run out of memory or doesn't take too long to search for each word.