Hi,
I'm trying to make a simple anagram solver, obviously using the already existing modules. I'm using Games::Word and Games::Word::Wordlist. A very simple version is online at
http://www.naveeng.com/fun/anagram.html. Its working fine except cases where a big word, i.e more than 8-9 characters is being provided. The process running the script stays in the memory for an awful lot of time, taking 99.9% of CPU usage, due to which it is being killed by the webhost. However, for 6 or even 7 characters, script gets successfully executed in seconds, hardly taking any CPU usage.
Also, the module Games::Word had a loop of the format for (0..upper limit) to calculate the permutations of the given string by calling the factorial() function of the module Math::Combinatorics , which was giving the error "Range iterator outside integer range" when a big word was given. However, I changed the loop to the format for (my $i=0;$i <= limit; $i++; ), after which it does not give that error. I suppose it is a system limitation.
Any pointers on which part of the whole process might be the reason for the script taking so long and eventually dying? I understand that with high number of characters, the factorial is huge and overheads increase, but here something else is wrong i guess.
Or if anyone can suggest a method to debug the issue, and/or a better alternative to go about solving anagrams?
I know that writing everything from scratch without using any module, is a possible solution, which I will do once all hopes on this one fail. Just wanted to know the probability of facing the same roadblocks in that case too.
Regards,
Naveen