Phone Words
Programming Quality Challenge #2
Problem Description
Each digit on a standard telephone dial has three alphabetic characters
associated with it:
2 = ABC
3 = DEF
4 = GHI
5 = JKL
6 = MNO
7 = PRS
8 = TUV
9 = WXY
(Digits 0 and 1 have no letters associated with them.)
Given a seven digit phone number, we could attempt to create a word
by choosing letters from the dial that correspond to each digit in the
number. For example, the Cal Poly computer science department office number
756-2824 could be SLOBTAG. Each seven digit phone number has 3 to the seventh
power letter combinations ("words") that could be associated with it.
Example
The output for 7562824 might begin like this:
PJMATAG
PJMATAH
PJMATAI
PJMATBG
PJMATBH
PJMATBI
Problem Requirements
Write a program which accepts a 7 digit string as a parameter on the command
line and produces all possible "words" that could be generated by different
combinations of letters on the phone dial. List the words (uppercase)
one per line
(left justified) to standard output. The digits 0 and 1 are output unchanged.
The output should list all combinations including the repetitions that
occur when the input contains a zero or one.
It is not necessary to determine if the generated "word" is a valid
english word.
The output doesn't have to be in any particular order.
If the input is not exactly seven digits, or contains non-numeric digits,
simply echo the input to standard output and terminate.
Implementation Guidelines
There are MANY possible ways to implement this algorithm. Performance considerations
are not a concern, so just use the simplest or most obvious design that
occurs to you.
Note: Please design your own solution. While this algorithm is easy
to find on the Web or in textbooks, please write your own algorithm from
scratch.
Testing
Create test cases that show your program can produce the correct results
-
For input containing all the digits 2 - 9.
-
For input containing digits 0 and 1.
-
For invalid input.
Include in your submission package execution output of your test results.
Each test run will produce over 2000 lines of output but lets try to conserve
a few trees; it is only necessary for you to submit the first page. The
input data for each test run should be hand written at the top of the page.