Introduction to Programming

Assignment 4


Date: Fri, 17 September 2004

Due on: Fri, 24 September 2004


Word building

Word building is a game whose rules are as follows. The first person says a word. By rotation, each player then has to say a new word that begins with the last letter of the previous word and has not been said before. The game ends when a player cannot produce a new word that meets the requirements.

Of course, all players have to agree that the words being used are legal, so the players have to have a common dictionary to refer all complaints.

A play of a word building game is a sequence of words from the dictionary that follows the rules but that cannot be extended further. For instance, if the dictionary consists of the words [bat,cat,tab,talc], then the collection of all possible plays is:

          bat-tab
          bat-talc-cat-tab
          cat-tab-bat-talc
          cat-talc
          tab-bat-talc-cat
          talc-cat-tab-bat
    

Write a function wordbuilding to enumerate all possible plays for a dictionary. The dictionary is provided as a list of words. For instance:

          wordbuilding ["bat","cat","tab","talc"] =
                                    [["bat","tab"],
                                     ["bat","talc","cat"],
                                     ["cat","tab","bat","talc"],
                                     ["cat","talc"],
                                     ["tab","bat","talc","cat"],
                                     ["talc","cat","tab","bat"]]
                 

     

Madhavan Mukund
Last modified: Fri Sep 17 10:26:09 IST 2004