University of Calgary

phone numbers

Phone Numbers to Words
[Assignment Idea: Roman Levandovsky, Student in Cpsc 231, 1999]

It has become quite common these days for businesses to associate their telephone numbers with words that people can remember more easily. For example, Sears Canada's catalogue number is: 1-800-26-SEARS.

The digits 2-9 on a telephone key pad are each associated with three letters of the alphabet:

2 A-B-C 6 M-N-O
3 D-E-F 7 P-R-S
4 G-H-I 8 T-U-V
5 J-K-L 9 W-X-Y

Notice that the digits 1 and 0 do not have letters associated with them. Notice also that only 24 letters are represented. The letters Q and Z are not in the table.

Your job is to write a program that will take a 7-digit phone number and generate a list of possible words that can be associated with it using a standard mapping of digits to letters. Since there are 3 possible letters for each digit, for a 7-digit number, there are approximately 37 = ~2200 possibilities. If you also include 6-letter words, there are an additional 36 = ~725 (assuming you only choose on the last 6 digits and not the first). There are ~250 5-letter words and finally ~80 4-letter words (assuming again you only check the rightmost digits). This makes a grand total of 3250 different combinations.

This is a very long list. In order to keep the output to this program manageable, let's look only for 5-letter words. This would leave the first 2 digits of the number in their "raw" state. Even then, we should be able to eliminate a fair number of these using a few simple approaches:

1. Any 'word' produced (mapping) that does not contain a vowel can be eliminated since it is unlikely to be a word.
2. Any phone number that contains a 1 or 0 anywhere in the 5-digit 'target zone' can't be converted.

Even with the ability to eliminate a fair number of candidates, the list is likely to be quite long. Make sure you format you output to print more than one phone-word per line.

When you run your program, re-direct output to a file so you don't need to see all the output.

If you are doing more than 5-digits DO NOT print the entire output file!!!! Instead use UNIX's 'head' and 'tail' commands to display the first and last 50-100 lines.

BONUS:

  1. Allow the user to choose which 5-digit 'set' to use in the search (include the option 'ALL'). [i.e. start with digit 3: ddd-dddd -> ddL-LLLL]
  2. Allow the user to try more than one number (one after the other).
  3. Allow the user to choose a range for the word size (i.e. 7-letter through 4-letter words - include the option 'ALL')
  4. Sort the output in alphabetical order.
  5. Check the output against the system's spell-checker ('spell') and eliminate non-words. Create a shell script for this.



Updated: August 10, 2005 09:56 AM