It is possible to number all the words that could be formed from a specified
alphabet. One way to do it is to put the words in order based on length, with
words of common length ordered alphabetically. Using this scheme, if we use
the alphabet consisting of just the 3 letters 'a', 'b', and 'c' then
the words are numbered:
1:a 2:b 3:c 4:aa 5:ab 6:ac 7:ba 8:bb etc.
There are an infinite number of possible words, but each has its own positive
number.
We want to be able to find the word that corresponds to any given number.
Create a class WordNumber that contains a method theWord that is given alpha,
the number of letters in the alphabet, and n, the number of a word. It
returns the String that is the word corresponding to n.
The alphabet to be used is the first alpha letters of the normal lowercase alphabet,
with their usual alphabetical ordering.
|