Code golf: find all anagrams
Posted
by Charles Ma
on Stack Overflow
See other posts from Stack Overflow
or by Charles Ma
Published on 2010-04-02T09:23:09Z
Indexed on
2010/04/02
9:33 UTC
Read the original article
Hit count: 720
An word is an anagram if the letters in that word can be re-arranged to form a different word.
Task:
Find all sets of anagrams given a word list
Input:
a list of words from stdin with each word separated by a new line
e.g.
A
A's
AOL
AOL's
Aachen
Aachen's
Aaliyah
Aaliyah's
Aaron
Aaron's
Abbas
Abbasid
Abbasid's
Output:
All sets of anagrams, with each set separated by a separate line
Example run:
./anagram < words
marcos caroms macros
lump's plum's
dewar's wader's
postman tampons
dent tend
macho mocha
stoker's stroke's
hops posh shop
chasity scythia
...
I have a 149 char perl solution which I'll post as soon as a few more people post :)
Have fun!
© Stack Overflow or respective owner