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.