Graal Forums Programming Exercise #2
 FAQ Members List Calendar Search Today's Posts Mark Forums Read

#16
01-15-2008, 07:25 PM
 Chompy ¯\(º_o)/¯ Join Date: Sep 2006 Location: Norway Posts: 2,815
 PHP Code: ``` /* Loops through a given wordlist        First checks if the current word in the wordlist    contains the letters the checking word does    then checks the length of the current    word and the checking word*/function findanagram(word) {  temp.wordlist = getwordlist();  temp.matches = "";  for(temp.currentword : wordlist) {    temp.y = "";    temp.cword = uppercase(currentword);    temp.word2 = uppercase(word);    // Checking     for(temp.i = 0; i < cword.length(); i++) {      if (word2.pos(cword.charat(i)) > -1) y @= "y";      else y @= "n";    }    if (y.pos("n") == -1) { // Checking purposes      temp.locw = cword.trim().length(); // length of currentword (for loop)      temp.low = word2.trim().length(); // length of word (params)      if (locw == low) {// if length of both comparing words are the same        if (currentword != word) matches @= currentword @", ";      }    }  }  if (matches.length() > 0) {     return matches;  }}// Edit this to return the wordlist usedfunction getwordlist() {  temp.list.loadlines("temp/wordlist.txt");  return list;}  ``` And you need to set maxlooplimit if your wordlist count is higher then the loop limit :o Edit getwordlist() at the bottom to return the wordlist used. I used a wordlist which I uploaded to temp (if anyone wants to try with that I can rar it and attach, but you might need to edit it (graal doesn't like to loop through 317k words )) :O And.. don't hurt me if this isn't a good anagram finder
 __________________
#17
01-15-2008, 09:11 PM
 Tolnaftate2004 penguin. Join Date: Jul 2004 Location: Berkeley, CA Posts: 534
Quote:
 Originally Posted by Chompy And.. don't hurt me if this isn't a good anagram finder
For words longer than 9 unique letters this is "eh, it's 'okay'."

In a perfect world, we could have a dictionary in a sort of hash table:
NPC Code:
```function anagrams( word )
sort letters in word;
calculate hashkey from letters;
return hashtable[hashkey];```

 __________________ ◕‿‿◕ · pfa · check yer syntax! · src Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/
#18
01-16-2008, 09:30 AM
 Kristi Bowie's Deciple Join Date: Dec 2003 Location: Boston, MA Posts: 748
Quote:
 Originally Posted by Tolnaftate2004 For words longer than 9 unique letters this is "eh, it's 'okay'." In a perfect world, we could have a dictionary in a sort of hash table: NPC Code:```function anagrams( word ) sort letters in word; calculate hashkey from letters; return hashtable[hashkey];``` TADAA
thats almost what i was looking for!
 __________________
#19
01-17-2008, 10:53 PM
 Tolnaftate2004 penguin. Join Date: Jul 2004 Location: Berkeley, CA Posts: 534
Quote:
 Originally Posted by Kristi thats almost what i was looking for!
You want the hash algorithm? I'm thinking a hash table of about 30^26 elements would do the job. :P
 __________________ ◕‿‿◕ · pfa · check yer syntax! · src Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/

Last edited by Tolnaftate2004; 01-17-2008 at 11:16 PM.. Reason: Redundancy? And spelling!
#20
01-23-2008, 06:34 PM
 Kristi Bowie's Deciple Join Date: Dec 2003 Location: Boston, MA Posts: 748
 I'm guessing this hasn't been touched long enough no one will add to this. I would have presorted a file of all known words with the letters arranged in alphabetical order, then just saved that and used it until the end of time. example line from file: aanst=santa,satan,etc then when given a word, sort it and look it up (very fast). now if someone wants to take the best shot coding the sorting of the word file and the look up in gscript...
 __________________
#21
09-16-2008, 08:47 AM
 Tigairius The Cat Join Date: Jan 2007 Location: Missouri, USA Posts: 4,240
Quote:
 Originally Posted by Kristi I'm guessing this hasn't been touched long enough no one will add to this. I would have presorted a file of all known words with the letters arranged in alphabetical order, then just saved that and used it until the end of time. example line from file: aanst=santa,satan,etc then when given a word, sort it and look it up (very fast). now if someone wants to take the best shot coding the sorting of the word file and the look up in gscript...
This isn't exactly how you described it, using a less efficient method, but it works decently fast for what it does.

 __________________ “Shoot for the moon. Even if you miss, you'll land among the stars.”
#22
09-16-2008, 08:58 AM
 Tolnaftate2004 penguin. Join Date: Jul 2004 Location: Berkeley, CA Posts: 534
Quote:
 Originally Posted by Tigairius This isn't exactly how you described it, using a less efficient method, but it works decently fast for what it does. http://forums.graalonline.com/forums...ad.php?t=81856
From what I can see it's a lot slower (something to the order of number-of-words-in-the-dictionary slower).
edit: I just watched the video and it makes me think that it might be slower than that even...
 __________________ ◕‿‿◕ · pfa · check yer syntax! · src Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/

 Tags anagrams, programming-exercise