longestWord.frink

Download or view longestWord.frink in plain text format


// Program to find the longest word that can be made by appending or prepending
// letters to the beginning or end of an existing word.

a=eval[input["Enter procedure:  1.) append only  2.) prepend only 3.) both "]]

words = new set

// Read words into the wordlist.
// The wordlist files are part of the Moby wordlist project, available at:
//   http://icon.shef.ac.uk/Moby/
for word = lines["file:/home/eliasen/prog/mobydict/mwords/crossword.txt"]
   words.put[lc[word]]

wordQueue = ["a", "i"]

while (length[wordQueue] > 0)
{
   w = wordQueue.popFirst[]
   for c = char["a"] to char["z"]
   {
      ch = char[c]
      if (a==1 or a==3)
      {
         wnew = "$w$ch"         // Append letters
         if (words.contains[wnew])
         {
            wordQueue.push[wnew]
            println[wnew]
         }
      }
      if (a==2 or a==3)
      {
         wnew = "$ch$w"         // Prepend letters
         if (words.contains[wnew])
         {
            wordQueue.push[wnew]
            println[wnew]
         }
      }
   }
}



Download or view longestWord.frink in plain text format


This is a program written in the programming language Frink.
For more information, view the Frink Documentation or see More Sample Frink Programs.

Alan Eliasen was born 20163 days, 0 hours, 23 minutes ago.