Perl Quiz-of-the-Week #4
Mark Jason Dominus <[email protected]> Wed, 06 Nov 2002 18:18:01 -0500
| Newsgroups | gmane.comp.lang.perl.qotw.quiz-of-the-week |
|---|---|
| Organization | Plover Systems |
| Message-ID | <[email protected]> |
IMPORTANT: Please do not post solutions, hints, or other spoilers
until at least 60 hours after the date of this message.
Thanks.
IMPORTANTE: Por favor, no enviéis soluciones, pistas, o cualquier otra
cosa que pueda echar a perder la resolución del problema hasta
que hayan pasado por lo menos 60 horas desde el envío de este
mensaje. Gracias.
IMPORTANT: S'il vous plaît, ne postez pas de solutions, indices ou
autre révélations jusqu'à au moins 60 heures après la date de
ce message. Merci
WICHTIG: Bitte schicken Sie keine Lösungen, Tipps oder Hinweise für
diese Aufgabe vor Ablauf von 60 Stunden nach dem Datum dieser
Mail. Danke.
----------------------------------------------------------------
Two words are said to be 'anagrams' if the letters of one word can be
rearranged to form the other word. For example, in English, 'ascot'
and 'tacos' are anagrams; so are 'tacos' and 'coats'. A set of words
that are all anagrams of one another is an 'anagram set'. For
example,
ascot coast coats tacos
is an anagram set.
Letter case doesn't matter, so, for example, 'liberating' and
'Gilbertian' are considered to be anagrams.
Write a program, 'make_anagrams', which reads in a list of words, one
per line, and finds all the anagrams in the the word list. It should
output an anagram dictionary, as follows:
* 'Words' that contain digits or punctuational characters should be
discarded.
* Anagram sets that contain only one word should be omitted from the
output.
* If an anagram set contains two words, say 'halls' and 'shall', the
output should contain two lines:
halls shall
shall halls
* If an anagram set contains more than two words, the entire set
should be listed under the alphabetically first word; the others
should cross-reference it. For example:
headskin nakedish sinkhead
nakedish (See 'headskin')
sinkhead (See 'headskin')
* The output lines should be in alphabetic order.
For example, if the input was
5th
ascot
ate
carrot
coast
coats
cots
Dorian
eat
halls
headskin
inroad
nakedish
ordain
Ronald's
shall
sinkhead
tacos
tea
then the output should be:
Dorian inroad ordain
ascot coast coats tacos
ate eat tea
coast (See 'ascot')
coats (See 'ascot')
eat (See 'ate')
halls shall
headskin nakedish sinkhead
inroad (See 'Dorian')
nakedish (See 'headskin')
ordain (See 'Dorian')
shall halls
sinkhead (See 'headskin')
tacos (See 'ascot')
tea (See 'ate')
If you need a sample input, you may obtain English word lists from
http://perl.plover.com/qotw/words/
If you prefer to do this quiz in a language other than English, please
substitute whatever conventions are appropriate for that language.