Write an algorithm to solve word ladders such as Word Meld 1
or Word Meld 2
. Input consists of the
starting and ending words and the maximum number of steps allowed. Available are files containing lists of
words of any given length; call one such file, say WORDS5.TXT containing a list of words of 5 letters each, and so on.
(In reply to Defining
I assume you are referring to my assumption of FindAdjacentWords, and the notion of having a tree template class (or equivalent, which exists in most mature programming libraries).
If so, then you are arguing about a matter of degree....
Charlie didn't explicitly say I have a PRINT command, nor an END PROGRAM command, nor collection objects, nor iterators (to move through the collection, perhaps in order), nor loop control operators (REPEAT, FOR EACH).
I must assume a modicum of basic understanding and familiarity with a computer language, and Charlie asked for an algorithm. I trust that what I proposed is sufficiently clear to actually write code in a language of your choosing.
Again, feel free to ask questions if this is in any way unclear.
However, all that being said....
Tree is straightforward enough... (if you've taken a basic computer algorithms class).
The FindAdjacentWords function could be implemented algorithmically as follows:
fWords.Open("WORDS" + CurrentWord.Length + ".TXT")
while not fWords.EOF() // EOF = end of file
WORD Word = fWords.GetNextWord()
If ( IsAdjacent(InitialWord, Word) == TRUE) Then
For Each Letter X in Word1
If (X is different than corresponding letter in Word2) Then
cDifference = cDifference + 1
if (cDifference == 2) then
if (cDifference == 0) then
Edited on September 24, 2003, 4:59 pm