Jumble solver



COMP 110

Spring 2009

Jumble solver

Due April 1, 2009 (no fooling)

Objectives Perform a search

Manipulate strings

Start by looking at the Daily Jumble:

()

These puzzles consist of a series of words whose letters have been rearranged. Your job is to figure out the word. In these puzzles, each scrambled word has only one unscrambled solution. In general, however, a scrambled word may have many solutions. For example, "tsop" can be unscrambled into "stop", "tops", "spot", and "post"

We will solve this problem by brute force. That is, we will throw computing resources at the problem to solve it in a very straightforward way.

1. Read the dictionary

Go to the course web site and click on the link for the Program 5 dictionary. This should open a text window containing the dictionary. Save it as dictionary.js in your local directory.

Put the following into your html in the head

This will create an array called list with just over 25,000 strings. The strings contain both upper and lower case letters plus some other characters.

2. Convert all the strings in the dictionary to lower case. Hint: if s is a string variable, then

s.toLowerCase()

is the lower case version of s. All upper case letters are converted; all other characters are unaffected. Note that toLowerCase() doesn't change s; you have to do that with an assignment statement. Converting the dictionary to lower case takes about 4 lines of code (of which 2 are just brackets).

3. Use html to generate text boxes to enter up to four jumbled words and output area. Include simple instructions to the user, plus GO and RESET buttons.

4. The program: The user will enter jumbled words into the text boxes and press GO. All the un-jumbled words should appear in the output boxes. See the example. Your page need not look exactly like this one, but should contain the same basic parts. The text area at the bottom shows how many dictionary words were tested. Note that if you enter an un-jumbled word (for example, "stop" and "beat"), this word will appear in the output box along with possibly others. If there are no matches, display an appropriate message. This program will work for lots of jumbles words, but not all. The dictionary does not contain plurals or various verb forms, so some searches will be unsuccessful. Don't worry about this.

5. Etc. Hint on using eval. You can build a string containing a JavaScript instruction, then execute it with eval. For example, the following loop sets the value of four text areas (named t1, t2, t3, and t4, all in a form called f1) to blank.

for (var i=1; i ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download