Thread: Anagrams!!!
View Single Post
  #7  
Old 09-21-2008, 07:54 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
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.== 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";
    
screenwidth 182 2;
    
screenheight 211 2;

    new 
GuiTextCtrl("AnaPanel_Text1") {
      
profile GuiBlueTextProfile;
      
height 20;
      
text "Enter Anagram:";
      
width 75;
      
10;
      
9;
    }
    new 
GuiScrollCtrl("AnaPanel_MultiLineEdit1_Scroll") {
      
profile GuiBlueScrollProfile;
      
height 71;
      
hscrollbar "dynamic";
      
vscrollbar "dynamic";
      
width 156;
      
11;
      
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;
      
87;
      
10;
    }
    new 
GuiTextCtrl("AnaPanel_Text2") {
      
profile GuiBlueTextProfile;
      
height 20;
      
text "Enter Word:";
      
width 57;
      
10;
      
148;
    }
    new 
GuiTextEditCtrl("AnaPanel_TextEdit2") {
      
profile GuiBlueTextEditProfile;
      
height 20;
      
text "";
      
width 98;
      
69;
      
148;
    }
    new 
GuiButtonCtrl("AnaPanel_Button1") {
      
profile GuiBlueButtonProfile;
      
text "Solve";
      
width 80;
      
47;
      
111;
    }
    new 
GuiButtonCtrl("AnaPanel_Button2") {
      
profile GuiBlueButtonProfile;
      
text "Scramble";
      
width 80;
      
47;
      
175;
    }
  }
}

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

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

function 
unscramble(msg) {
  
msg lowercase(msg);
  for (
temp.0temp.msg.length(); temp.++) {
    
temp.explode.add(msg.substring(i1));
  }
  
temp.explode.sortascending();
  for (
temp.iexplode) {
    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(0msg.length()));
    if (
temp.d.index(rando) < 0) {
      
temp.output @= msg.substring(rando1);
      
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.
Attached Files
File Type: zip words.zip (3.46 MB, 10228 views)
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”

Last edited by Tigairius; 09-21-2008 at 08:12 AM..
Reply With Quote