Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Anagram Generator

Status
Not open for further replies.

mp2001

Programmer
Dec 6, 2001
2
GB
Hello, does anyone know how to program an anagram generator without the use of a dictionary.

I can just about return the permutations but unfortunately not very well.

I am using VBA, so if any VBA buffs would like a challenge or wouldn't mind giving advice I would most appreciate it.
 
What do you mean " ... without the use of a dictionary ..."?


Are you providing a word list for use, and restricting the anagram to the use of words in the list?


MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
I am trying to get the permutations of a given word and then apply common-sense rules to the new word strings (e.g. no more than 2 vowels together).

The words then have to be ranked and displayed within a form (probably top 10 or 20). I have the folowing code:

Sub ListWords(word)
For i = 1 To Len(word)
Debug.Print Mid(word, i, 1);
rest = Mid(word, 1, i - 1)
rest = rest & Mid(word, i + 1, Len(word) - i)
If Len(rest) > 1 Then
ListWords rest
Else
Debug.Print rest
End If
Next
End Sub

Sub main()
ListWords "DOG"
End Sub

unfortunately I can only get it to print to changed letters and not the entire word.

Cheers, Matt.
 
Hmmmmmmmmmmmmmm,

To many issues to reasonably state (all of) them.

I did include a slightly modified version of your procedure, which will at least let you "see" your product in action. I have never considered using a recursive function to actually RETURN the Permutations of a collection, and -off hand- do not see a way to make your procedure (accurately) return the permutations of a collection of letters (the string argument). You will note that I have included a static variable in hte revised code (RecurseCount) and an optional boolean in the argument list. You should try the revised routine with some short "words" (I would suggest 3 to 6) and 'review' the results. To "see" this in action, try it from the immediate window, as in:

? LIstWords("Dog", True)

or

? ListWords("Matt", True)

As for using "common sense" rules for generating "words" in the english language, I am sure that one of us is completly out of the running on generating the list of such rules which would come even close. Further, these "rules" would almost certainly generate quite a few character strings which were NOT recognized by the dictionary police. You should recognize that "English" (and particularly "American English") inherits 'words' from many languages, and in many instances, we have accepted the foregin "spelling" which may not fit nicely into the "common sense" rules of spelling.


Code:
Public Function ListWords(word As String, Optional Init As Boolean = False)

    'Michael Red, Dec 7, 2001
    'How to NOT use Recursion.

    Static RecurseCount As Long

    If (Init = True) Then
        RecurseCount = 0
    End If

    RecurseCount = RecurseCount + 1

    For i = 1 To Len(word)
      rest = Mid(word, 1, i - 1)
      rest = rest & Mid(word, i + 1, Len(word) - i)
      If Len(rest) > 1 Then
        ListWords (rest)
      End If
    Next

    Debug.Print rest

    If (Init = True) Then
        Debug.Print RecurseCount
    End If

End Function

MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top