04-27-2024, 02:01 PM
(04-27-2024, 06:29 AM)Circlotron Wrote: What I have managed to do for my anagram finder to speed things up a whole lot is to have a the big word list, also a number of smaller files, each one containing words of equal length, also matching files containing L-R sorted versions of the same words in the same order. These files are named 3,4,5 etc and 3S,4S,5S etc. When a word from the main file is read, the length of that word opens the corresponding word length file and the matching sorted word file. These are a lot shorter than the big file, so a full scan of these is way quicker than a full length file. What's more, both the equal length word file and it's corresponding sorted file are read together, so when a sorted match is found, the corresponding anagram is read directly from the equal length file. The point is, the words being tested don't have to be sorted repeatedly on the fly, this is already done and stored in the sorted file. Edit -> These changes have sped things up by a factor of 9.2 times.
i did the Rosetta Code challenge for anagrams about 7 years ago, steve too so don't remember exactly what was done then... i'd be inclinded to write an 2 word array with the anaCode for the first word then the word for second, then sort it by first word key, so all like anacodes are bunched together and just read down the array looking for the biggest bunch.
b = b + ...