PDA

View Full Version : Anagrams!!!


Tigairius
09-16-2008, 09:25 AM
pz0kUYkhsh4

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, 09:47 AM
Oh man. I could see this leading to a lot of bad attempts at future word filters. Ha.

DrakilorP2P
09-16-2008, 11:24 AM
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, 02:35 PM
Not bad :)

Crow
09-16-2008, 03:58 PM
Checking your chat message for swears, please stand by...

Lol, that would be so annoying ;D

cbk1994
09-16-2008, 11:20 PM
Very cool. :)

Tigairius
09-21-2008, 08:54 AM
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:

// 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, 09:16 AM
Very nice, much faster than before!

http://img441.imageshack.us/img441/4679/picture12wn7.png

Kristi
09-21-2008, 10:08 PM
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, 06:50 PM
It's funny because I needed to unscramble some words for my homework...

Tigairius
09-23-2008, 07:03 PM
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, 07: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.