mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Dec 2002
Posts: 111
E
Vogon poet
OP Offline
Vogon poet
E
Joined: Dec 2002
Posts: 111
code:

Code:
on *:text:*:#: {
  var %word = chocolate 
  var %wordfind = $1, %char
  while $left(%wordfind, 1) != $null {
    %char = $ifmatch
    if ($count(%wordfind, %char) > $count(%word, %char)) { msg $chan Found Word! }
    %wordfind = $remove(%wordfind, %char)
  }
}



I posted about this a while back and just now got into attempting to do it again. This is code what someone else put on this board and said it would work when I posted earlier, so now I am attempting to do use it :P (several months later). Anways, as you can see I set the word for it to search in as Chocolate, then I want it to look at whatever else is spit out into the channel. If a word can be made from those letters (IE, Loco, Choco, Locate, etc), even if they are mixed up, I want it to message the channel "Word Found!". Well, what i have up there isn't workin like i thought it would shocked It's spittin out random stuff:

Code:
<EviL_SmUrF> a
<EviL_SmUrF> as
<WordBot> Found Word!
<EviL_SmUrF> asd
<WordBot> Found Word!
<WordBot> Found Word!
<EviL_SmUrF> asdf
<WordBot> Found Word!
<WordBot> Found Word!
<WordBot> Found Word!


Any and all help is appreciated!

Thanks,
Russell

Last edited by EviL_SmUrF; 07/05/04 05:20 AM.
Joined: Aug 2003
Posts: 325
W
Fjord artisan
Offline
Fjord artisan
W
Joined: Aug 2003
Posts: 325
What you are asking for, if I understand correctly, is not really possible without having an extensive dictionary available. The code you supplied will trigger true if someone types in anything (in the first word) with either 1 a, e, h, l ot t -or- 2 c's or 2 o's. Here's something that will see if enough letters were used to make the word "chocolate". I hope this gives you a better start to what you are looking for...

Code:
on *:text:*:#: {
  var %word = chocolate, %char
  while (%word) {
    %char = $left(%word,1)
    if ($count(%word, %char) > $count($1-, %char)) { return }
    %word = $remove(%word,%char)
  }
  msg $chan Found word!
}

Untested but see if that works better... cool

Joined: Dec 2002
Posts: 111
E
Vogon poet
OP Offline
Vogon poet
E
Joined: Dec 2002
Posts: 111
I actually have a text file that has just about every single word in the english language in it, which I am going to use to test words that users pump out into the channel.

So the code I posted was correct?

If so, how come it was spitting out "word found" several times instead of just once? cause the only letter in the word "Chocolate" that matched was the "a" from 'asdf'. Aside from that, it shouldnt have even tested true anyways since the s, d, and f, arent even in %word. I'm not trying to test how many letters are used, I just need to test that those letters only cosist of the letters that are used to make up the word that is set in %word, even if they are mixed up. It can ONLY consist of the letters that are in %word, nothing else. Then I will have the script check the word that the user spit out in the words.dat file.


Thank you for your help!!!!!

Joined: Feb 2004
Posts: 206
D
Fjord artisan
Offline
Fjord artisan
D
Joined: Feb 2004
Posts: 206
Here is an algortihm:

1 - order letters in target word (chocolate --> accehloot)
2 - order letters in check word (hoot --> hoot blushops! a no brainer example!)
3 - seek for common letters and "cross off" as you go through.

While step 2 may not be necessary - it might make stepping through the words easier.

I haven't tried coding this - but I am sure that some of those more expereinced than I could make a quick code up :-)

Cheers,

DK


Darwin_Koala

Junior Brat, In-no-cent(r)(tm) and original source of DK-itis!
Joined: Aug 2003
Posts: 325
W
Fjord artisan
Offline
Fjord artisan
W
Joined: Aug 2003
Posts: 325
Quote:
So the code I posted was correct?
No, it wasn't.

Quote:
If so, how come it was spitting out "word found" several times instead of just once? cause the only letter in the word "Chocolate" that matched was the "a" from 'asdf'. Aside from that, it shouldnt have even tested true anyways since the s, d, and f, arent even in %word.
I told you why. The code you used returns true when it finds one letter that matches the requirements. In the example you gave, the letter a matches. So using any combination of asdf would make a match.

Problem with what you want is that if you sort the letters, then you have some words that have the same letters and you have to decide which word to use. Only way I could think of (and I'm not sure if it can be done this way) is to use hash tables. Read in ALL the words and then search for the the words inside of what the person typed. However that wouldn't take care of the rearranging of the letters, only the same order. There might even be a way using regular expressions. But that is all stuff that would be very slow if you don't make use of tools such as $regex (regular expressions) and hash tables for increased speed, otherwise your mirc could spend several seconds, at least, trying to anaylze each sentence to look for words.

Joined: Dec 2002
Posts: 111
E
Vogon poet
OP Offline
Vogon poet
E
Joined: Dec 2002
Posts: 111
hm, damn. i need to figure out how to do that.

will $regex be able to see say, "locate" from "chocolate"?

Joined: Aug 2003
Posts: 325
W
Fjord artisan
Offline
Fjord artisan
W
Joined: Aug 2003
Posts: 325
With the proper regex, I *think* that it would be able to find if there are enough matching letters to form that word.

The main problem would be programming a regex for each word you would want it to find, and this is assuming that the method I said is actually possible.


Link Copied to Clipboard