Definition: an anagram of a word (for instance, "spot") is another word with the same letters, but in a different order (for instance, "stop" or "pots").
Many years ago, a dinner companion asked me, as a puzzle: What English word is an anagram of the word "carthorse". Of course, I immediately said "horsecart", but that turns out not to be an English word. At the time, I was lazily learning Java, but the question motivated me, that very evening, to wrote my first Java program in order to solve that puzzle. Now, you can pretty easily solve this puzzle by asking someone who knows the answer (it's a well-known puzzle), or going to some internet site that will tell you the anagram of any word you enter. That, of course, is not the point of the homework.
Here is the list of about 80,000 English words you're going to use. Download it, and look at it (always eyeball your data first).
Definition: an anagram-family is a set of all words (from a list of English words) that are anagrams of each other. For instance, this is an anagram-family: ['opts', 'tops', 'spot', 'stop', 'pots', 'post']. An anagram-family must contain more than one member, so words without anagrams are not in families.
Exercises:
Using the dictAll.txt list of English words, answer the following questions. For each question with a "to Comments" at the end: put its answer into the Comments-to-Teacher
1. What is the anagram (there's only one) of "carthorse"? "to Comments"
2. Of "mountaineers"? "to Comments"
3. Of "triangulated"? "to Comments"
4. Challenge: create all the anagram families from the word-list. Hint: create a dictionary with the key being a word and the value being the anagram-signature of that word (see the hint below for what an anagram-signature is). Then invert that dictionary. That will give you all the anagram-families.
4a) The sample anagram-family (['opts', 'tops', 'spot', 'stop', 'pots', 'post']) has 6 members. There are a few anagram families with 7 members. Find them. "to Comments"
Here is a hint that you should look at only if you haven't found a good way to solve any of the problems...