duckduckgo/zeroclickinfo-goodies — pull request #163 by beardlybread (2013-02-18 01:11:39+00:00)
Title: Anagram Solver

As a quick aside, thank you again for inviting us to visit this past Friday. I am the grumpy looking bald guy who sat in the corner named Brad.

A couple points:
1. This is a quick hack that requires no a priori processing of the dictionary and simply uses a newline delimited list of words.
2. From my brief ad hoc testing, it performs reasonably well on the (/usr/share/dict/) words dictionary on my system (wc for the file is 99171). It is hard coded to that path, so this may need to be changed.
3. The current trigger word is "flargblarg," which is not descriptive to say the least.

A quick run-down on the logic:
- Initialize input variables
- Create a hash of the frequency of each letter in the input word
- For each word in dictionary:
- If /^[$word]{$n}$/ does not match, skip. My reasoning is that this step eliminates a large number of words immediately: words with the correct number of letters and only letters in the input word are the only ones that need to be tested for "anagram-ness."
- Otherwise, generate a letter frequency hash for the dictionary word. If the frequency jives with input word, add it to output.

If you have any questions or comments, please feel free to email me. I've only very briefly messed around with Perl in the past, so any input would be appreciated. I figured I'd start with something simple and maybe try my hand at something more complicated later.

If this comment is way too much information and you'd prefer that I use a different channel, don't hesitate to tell me. I don't want to be mucking up your github with pull requests if you'd rather I polish things better beforehand.

Regards,
Brad Steinbacher
bjs5531@psu.edu