When entering your code, you are free to use the arrow keys to move around and the backspace key to erase erroneous code. To erase an entire section of code, you can highlight the code (hold down the left mouse button and drag the cursor over the section of code) and then hit backspace. Note that if there are errors in your code, you can always go back and fix them and try again. The contents of the text box persist after executions, so you can repeatedly edit and execute the same piece of code.
Once you have your code debugged (the computer term for error-free), execute it five times and list the letter sequences that were generated.
To save a document in the Text Editor, select save under the File menu. You will be prompted for a file name, and the contents of the document will then be saved under that name. Once you have saved the document, a document icon with that name should appear in the File Manager window. To reopen that document at a future time, you can simply double click on the icon, or else select Open from the File menu in the Text Editor.
Execute your code repeatedly, counting the number of executions until you obtain a word. Do this 5 separate times and list the number of executions needed for each word. Do your experimental results support the theoretical prediction of 32 executions per word? If not, can you explain why?
As the length of the letter sequences increases, the chances of generating a word at random decreases dramatically. For example, there are 1,777 4-letter words in the online dictionary. Thus, the chances of generating a 4-letter word at random are 1 in 257 (264/1,777 = 456,976/1,777 = 257). For 5-letter sequences, the chances of generating a word at random is 1 in 4,920 (265/2,415 = 11,881,376/2,415 = 4,920) .
Part of the blame for the scarcity of words among randomly generated sequences falls on letters such as 'q' and 'z'. Since these letters are used so infrequently in English, their inclusion in a random sequence of letters makes a real word extremely unlikely. If we exclude letters such as these, however, we can improve the chances of generating words considerably. For example, the 10 letters that appear most frequently in English text are "etaoinshrd". Random sequences of these letters would appear more likely to produce words.
Similar to EXERCISE 5, execute your modified code repeatedly, counting the number of executions until you obtain a word. Do this 5 separate times and list the number of executions needed for each word.
Using your experimental results from the previous exercise, you should now be able to estimate the number of 3-letter words in the English language that use only the letters in "etaoinshrd". The following general formula applies:
Cut-and-paste a copy of your modified code at the bottom of your Lab1 document, below the original version. Hand in a printout of your Lab1 file, attached to these sheets.