Anagrams and Their Computer Solution by James Pate Williams, Jr., BA, BS, MSwE, PhD

An anagram is also known as a word jumble. You take a word and apply a permutation to the word to get an alphabetic jumble of the word. A permutation of three distinct characters is based on three index permutation table:

123 132 213 231 312 321.

So, the scrambling of the word “THE” is as follows:

THE TEH HTE HET ETH EHT.

As you can see there are n-factorial permutations of n objects.

0! = 1

1! = 1

2! = 2 * 1 = 2

3! = 3 * 2 * 1 = 6

4! = 4 * 3 * 2 * 1 = 4 * 3! = 24

Etc. Several years ago I created a program to solve single word anagrams of length less than or equal about a dozen.

12! = 479,001,600

This is about the limit of finding all the permutations of up to length twelve on a desktop computer. The algorithm is extremely easy to understand and implement. First find a suitable list of English words and if the list is unsorted then sort the list alphabetically in ascending order. Hash the dictionary words using a hash table of length 128 * 128 + 128 = 16,512 elements. The dictionary I used has 152,512 words so there are hash table collisions. The hash value is computed using the first three characters of the word in ASCII (7-bit) encoding. Then for each permutation of the anagram a hash value is computed and if the current permutation is found in the hash table the word associated with the hash table entry is returned and the algorithm is finished.

Unknown's avatar

Author: jamespatewilliamsjr

My whole legal name is James Pate Williams, Jr. I was born in LaGrange, Georgia approximately 70 years ago. I barely graduated from LaGrange High School with low marks in June 1971. Later in June 1979, I graduated from LaGrange College with a Bachelor of Arts in Chemistry with a little over a 3 out 4 Grade Point Average (GPA). In the Spring Quarter of 1978, I taught myself how to program a Texas Instruments desktop programmable calculator and in the Summer Quarter of 1978 I taught myself Dayton BASIC (Beginner's All-purpose Symbolic Instruction Code) on LaGrange College's Data General Eclipse minicomputer. I took courses in BASIC in the Fall Quarter of 1978 and FORTRAN IV (Formula Translator IV) in the Winter Quarter of 1979. Professor Kenneth Cooper, a genius poly-scientist taught me a course in the Intel 8085 microprocessor architecture and assembly and machine language. We would hand assemble our programs and insert the resulting machine code into our crude wooden box computer which was designed and built by Professor Cooper. From 1990 to 1994 I earned a Bachelor of Science in Computer Science from LaGrange College. I had a 4 out of 4 GPA in the period 1990 to 1994. I took courses in C, COBOL, and Pascal during my BS work. After graduating from LaGrange College a second time in May 1994, I taught myself C++. In December 1995, I started using the Internet and taught myself client-server programming. I created a website in 1997 which had C and C# implementations of algorithms from the "Handbook of Applied Cryptography" by Alfred J. Menezes, et. al., and some other cryptography and number theory textbooks and treatises.

Leave a comment