Jump to content

How to go about creating an anagram solver?


Rifts

Recommended Posts

You could look into finding a permutation script (there have been many posts on these forums) to generate all the different ordering of the letters. Then compare those to the possible words.

 

Although, if you have a target of words, then you could come up with a solution that counts the different letters and can compare that way. That would probably be more efficient. So, if the anagram and the target word have the same number of 'a', 'r', 's', etc. Then it is a solution.

 

I'd probably order the letters in the words from a-z and then compare.

If all you're trying to do is figure out if two words are anagrams of each other, sorting the words a-z will work really well. 

 

If you're trying to print a valid anagram, then as has been suggested provide a word list.

 

I'd maybe create an array then like this: 

 

array(

"abt" = > array( "bat", "tab" ), 
"enst" = > array( "sent", "tens", "nets" )

);

 

That way the key is a sorted version of all the possible words you want. 

Thanks these are great ideas the only problem is the mixed up word has extra letters. This is where I'm getting stuck.

 

Say the word is bat but the input is sfboart, and the user knows the word is 3 letters.

 

I'm getting confused because the extra characters.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.