Results 1 to 3 of 3

Thread: Anagrams

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fox, OK
    Posts
    381

    Anagrams

    I made a program to cheat at scrabble/word games. I can find words that "start with" a group of letters, "end with" a group of letters, or "contain" a group of letters in the middle. Furthermore, I can enter all my letters, and look for all the words that contain those letters. I can even enter a "*" for a blank tile (in Scrabble) and it will try all the possibilities for the blank tile.

    What my program doesn't do is find all the subanagrams. For example, if I enter the letters "BNAG", my program would find only 4-letter words. I want it to also find all the 2- and 3- as well as 4-letter words.

    What's the best logic/algorithm for grouping my letters into groups of 2, 3, 4, 5, etc.?

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fox, OK
    Posts
    381

    Re: Anagrams

    How about this....
    I assign a prime number to each letter in the alphabet.

    For each word in my "word list file" (which gets read into an array), I create a value which is the product of the values of the letters in that word.

    Now to check for subanagrams, I go through the word list and divide each word's value into the value of the letters that I'm anagraming. If I get no remainder, the that word is a sub anagram.

    'a'=>2,'b'=>3,'c'=>5,'d'=>7,'e'=>11,'f'=>13,'g'=>17,'h'=>19,
    'i'=>23,'j'=>29,'k'=>31,'l'=>37,'m'=>41,'n'=>43,'o'=>47,'p'=>53,
    'q'=>59,'r'=>61,'s'=>67,'t'=>71,'u'=>73,'v'=>79,'w'=>83,'x'=>89,
    'y'=>97,'z'=>101

    I suppose it would be best to give the most common letters the lowest values to keep the products smaller. Or will it matter?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fox, OK
    Posts
    381

    Re: Anagrams

    I tried this idea and it works most excellently. It's super fast and I'm able to easily split the subanagrams up by length. I have a listbox for 3-letter, 4-letter, etc. words.

    I did come across a problem. Initially, I created a new word list file that had each word paired with its "prime value". However, when the really larger number gets printed to the file, it's written in "E" notation and some of the numbers lose decimal places causing the values to not match the value of the letters I'm trying to anagram. I corrected this by creating the "prime values" on the fly as the word file is read into the array.

    Now that "anagrams" is complete (except for entering "*" for blank scrabble tiles), I'll work on "words that end with", "words that star with", and "words that contain", which should all be pretty simple.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width