One way of generating all anagrams for a word systematically is to use
numbers of a base correspondiing to the number of characters in the
word. Then, assign a "digit" to each letter of the word. If you have
a 4-letter word you will use a base 4 counter which will have a range
from 0000 to 3333. Enumerate all members of the range: 0000, 0001,
0002, 0003, 0010, 0011, 0012, 0013, 0020, etc. Select only those
members which have all different digits. E.g, 0123 would be the
first one, then 0213, etc. For each of these selected members,
substitute the letters corresponding to the original word. Thus, for
"abcd", a=0, b=1, c=2, d=3. Taking the first member from our
enumeration with 4 different digits, (0123) becomes (abcd), (0213)
becomes (acbd), etc.
If the original word has non-unique letters, some of your anagrams
will be duplicated. This process is sytematic and complete, but not
very efficient because a lot of the numbers have to be discarded
because they don't have unique digits. Also, as your word length
increases, so does the length of the process. An 8-letter word would
require an 8-digit, base-8 counter.
If you want to find all anagrams of a word in a dictionary, there are
better ways of doing this using word lengths and hash codes based on
letter content.
Good luck,
xyz
==============
On Tue, 30 Sep 2003 23:47:38 GMT, "Eric A. Johnson"
<aj****@earthli nk.net> wrote:
Hi,
Thanks for reading this. How do I list all possible permutations of a
word? I've figured out how to get all the characters in alphabetical order.
I then want to display every possible character permutation in sequence,
like so:
abcd abdc acbd acdb adbc adcb bacd badc bcad bcda bdac bdca cabd cadb cbad
cbda cdab cdba dabc dacb dbac dbca dcab dcba
This is turning out to be much more difficult than I thought it would
be. It seems to be that a recursive function or procedure, possibly using
the length of the string, might be a good idea... but since the number of
permutations is x!, where x is the length of the string, I don't quite know
where to begin. Can anybody give me some hints? Thanks!
Thanks,
Eric A. Johnson