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.

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.