Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Anagrams!!! (https://forums.graalonline.com/forums/showthread.php?t=81856)

Tigairius 09-16-2008 08:25 AM

Anagrams!!!
 
2 Attachment(s)

This script will create & solve (most) anagrams. As seen in the video above, it will work on most English words.

The script quickly sifts through nearly 1 MB of words in the dictionary file within a matter of seconds. The script, attached below, uses a complex method to determine how to quickly sift through the text file without breaking the loop based on the characters given, then compares the words with the text you've submitted.

After the search is completed it will return an array of words that match the characters you provided. For example, "tca" would return: act,cat

(Attached the script due to percent sign.)

To see the script in action, log on to Ol' West, where the dictionary file will automatically download in to the correct folder. Once you're on Ol' West, type ".anagram"

Have fun, hope someone learns something. :cool:

Draenin 09-16-2008 08:47 AM

Oh man. I could see this leading to a lot of bad attempts at future word filters. Ha.

DrakilorP2P 09-16-2008 10:24 AM

Quote:

Originally Posted by Draenin (Post 1423904)
Oh man. I could see this leading to a lot of bad attempts at future word filters. Ha.

Checking your chat message for swears, please stand by...

Dan 09-16-2008 01:35 PM

Not bad :)

Crow 09-16-2008 02:58 PM

Quote:

Originally Posted by DrakilorP2P (Post 1423910)
Checking your chat message for swears, please stand by...

Lol, that would be so annoying ;D

cbk1994 09-16-2008 10:20 PM

Very cool. :)

Tigairius 09-21-2008 07:54 AM

1 Attachment(s)
Okay, based on some helpful advice from Hell Raven (and the Programming Exercise #2 thread) and thanks to a USD bet Stephen and I had, I have rescripted the anagram solver.

Stephen and I had a bet that I could make a faster anagram solver with him using GS2 than he could with PHP. This anagram solver took the prize and put a little extra $ in my pocket.

Okay, anyways. Extract the zip file below in to your graal folder. The run the script below:
PHP Code:

// Creates & Solves Anagrams
// NPC made by Tig
//#CLIENTSIDE
function onCreated() {
  
AnaPanel_Window1.destroy();
}

function 
onPlayerChats() {
  switch (
player.chat) {
    case 
".anagram":
        
CreateWindow();
    break;
  }
}

function 
CreateWindow() {
  
player.chat = "Building Anagram Panel...";
  
sleep(0.01);
  
this.alpha = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "-"};
  
this.wordlist.loadvars("scriptfiles/english0.txt");
  if (
this.wordlist.a == null) {
    
player.chat = "You don't have the dictionary file.";
    return;
  } 
  
player.chat = "";
  new 
GuiWindowCtrl("AnaPanel_Window1") {
    
profile = GuiBlueWindowProfile;
    
clientrelative = true;
    
clientextent = "182,211";

    
canmove = true;
    
canresize = false;
    
canmaximize = false;
    
closequery = false;
    
destroyonhide = false;
    
showtop();
    
text = "Anagram Panel";
    
x = screenwidth / 2 - 182 / 2;
    
y = screenheight / 2 - 211 / 2;

    new 
GuiTextCtrl("AnaPanel_Text1") {
      
profile = GuiBlueTextProfile;
      
height = 20;
      
text = "Enter Anagram:";
      
width = 75;
      
x = 10;
      
y = 9;
    }
    new 
GuiScrollCtrl("AnaPanel_MultiLineEdit1_Scroll") {
      
profile = GuiBlueScrollProfile;
      
height = 71;
      
hscrollbar = "dynamic";
      
vscrollbar = "dynamic";
      
width = 156;
      
x = 11;
      
y = 33;

      new 
GuiMLTextEditCtrl("AnaPanel_MultiLineEdit1") {
        
profile = GuiBlueMLTextEditProfile;
        
height = 16;
        
horizsizing = "width";
        
text = "";
        
width = 131;
      }
    }
    new 
GuiTextEditCtrl("AnaPanel_TextEdit1") {
      
profile = GuiBlueTextEditProfile;
      
height = 20;
      
text = "";
      
width = 80;
      
x = 87;
      
y = 10;
    }
    new 
GuiTextCtrl("AnaPanel_Text2") {
      
profile = GuiBlueTextProfile;
      
height = 20;
      
text = "Enter Word:";
      
width = 57;
      
x = 10;
      
y = 148;
    }
    new 
GuiTextEditCtrl("AnaPanel_TextEdit2") {
      
profile = GuiBlueTextEditProfile;
      
height = 20;
      
text = "";
      
width = 98;
      
x = 69;
      
y = 148;
    }
    new 
GuiButtonCtrl("AnaPanel_Button1") {
      
profile = GuiBlueButtonProfile;
      
text = "Solve";
      
width = 80;
      
x = 47;
      
y = 111;
    }
    new 
GuiButtonCtrl("AnaPanel_Button2") {
      
profile = GuiBlueButtonProfile;
      
text = "Scramble";
      
width = 80;
      
x = 47;
      
y = 175;
    }
  }
}

function 
AnaPanel_Button2.onAction() {
  
AnaPanel_TextEdit2.text = scramble(AnaPanel_TextEdit2.text);
}

function 
AnaPanel_Button1.onAction() {
  
temp.p = timevar2;
  
AnaPanel_MultiLineEdit1.text = unscramble(AnaPanel_TextEdit1.text);
  
AnaPanel_MultiLineEdit1.text @= "\nSolved in " @ timevar2 - p @ " secs.";
  if (
AnaPanel_MultiLineEdit1.text.substring(0, 1) == 0) {
    
AnaPanel_MultiLineEdit1.text = "Not found.";
  }
}

function 
unscramble(msg) {
  
msg = lowercase(msg);
  for (
temp.i = 0; temp.i < msg.length(); temp.i ++) {
    
temp.explode.add(msg.substring(i, 1));
  }
  
temp.explode.sortascending();
  for (
temp.i: explode) {
    if (
i in this.alpha)
      
temp.word @= i;
  }
  return 
this.wordlist.( @ word);
}

function 
scramble(msg) {
  while (
temp.output.length() < msg.length()) {
    
temp.rando = int(random(0, msg.length()));
    if (
temp.d.index(rando) < 0) {
      
temp.output @= msg.substring(rando, 1);
      
temp.d.add(rando);
    }
  }
  return 
output;
} 

Some examples:
Anagram: srenio
Result: ireson,rosine,senior,serino,sonier,irones,noires,n osier,resino,soneri
Solved in 0.00074571 secs.

Anagram: fydlea
Result: fadely,flayed,deafly
Solved in 0.000312298 secs.

Anagram: anestri
Result: nastier,retains,anestri,asterin,eranist,ratines,re siant,restain,retina's,retinas,retsina,stainer,sta rnie,stearin
Solved in 0.000671716 secs.

It can also solve things like:
Anagram: Eh! A Speakers.
Result: shakespeare
Solved in 0.000570735 secs.

cbk1994 09-21-2008 08:16 AM

Very nice, much faster than before!

http://img441.imageshack.us/img441/4...cture12wn7.png

Kristi 09-21-2008 09:08 PM

Quote:

Originally Posted by Tigairius (Post 1425093)
Okay, based on some helpful advice from Hell Raven (and the Programming Exercise #2 thread) and thanks to a USD bet Stephen and I had, I have rescripted the anagram solver.

That's so cheap. Of course the one I help is going to win :P

xAzerothx 09-23-2008 05:50 PM

It's funny because I needed to unscramble some words for my homework...

Tigairius 09-23-2008 06:03 PM

Quote:

Originally Posted by xAzerothx (Post 1425733)
It's funny because I needed to unscramble some words for my homework...

What kind of homework do you have? I don't remember having to do that since the 2nd grade.

xAzerothx 09-23-2008 06:36 PM

Yea I know. Some of our teachers think we're retarded. It was advanced health homework and the teacher was asian who doesn't speak english very well.


All times are GMT +2. The time now is 01:12 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.