mIRC Home    About    Download    Register    News    Help

Print Thread
#126435 30/07/05 07:24 AM
Joined: Jun 2005
Posts: 44
B
BNX Offline OP
Ameglian cow
OP Offline
Ameglian cow
B
Joined: Jun 2005
Posts: 44
I have 6 variables:
%var.1
%var.2
%var.3
%var.4
%var.5
%var.6
I have 6 more variables
%iable.1
%iable.2
%iable.3
%iable.4
%iable.5
%iable.6


How do I check if ANY of the %var.* variables match with ANY of the %iable.* variables

if (%var.* == %iable.*) does not work. crazy

Is there a way to do this without scripting out all the permutations? XD

Joined: Feb 2004
Posts: 206
D
Fjord artisan
Offline
Fjord artisan
D
Joined: Feb 2004
Posts: 206
The only way I can see is a double loop (pseudo- code below)
Code:
  var %var.count = 6
var %iable.count = 6

while %var.count [> 0]
  while %iable.count [>0]
    if (%var $+ %var.count == %iable %+ %iable.count) {
      your code here
    }
    dec %iable.count
  } [next %iable]
  dec %var.count
} [next %var]



Cheers,

DK


Darwin_Koala

Junior Brat, In-no-cent(r)(tm) and original source of DK-itis!
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
As DK said, a double loop is the only way that I can see doing it also, and as his code is a pseudo-code.

The parts that should (and in come cases, need) to be left out are the sections enclosed in [ ]

Joined: Jun 2005
Posts: 44
B
BNX Offline OP
Ameglian cow
OP Offline
Ameglian cow
B
Joined: Jun 2005
Posts: 44
Ok, then it is non-trivial at the moment. In my script they are radnom every time the script is ran. It is a lotto script, where each player's numbers (6 of them) are matched with the 6 lotto numbers, if there is 1 match, perform a function.

Thanks. I reported this to the suggestions forum for a new $chkall() identifier :tongue:

Last edited by BNX; 30/07/05 08:45 AM.
Joined: Apr 2003
Posts: 701
K
Hoopy frood
Offline
Hoopy frood
K
Joined: Apr 2003
Posts: 701
Why 6 (no 6+ #players * 6) different variables?
Lotto numbers are short, so make one %var with as contents 1 5 45 58 23
and then use a simple loop using $istok.
Don't make things difficult for yourself...


here's an example, change the return command to return what you need

Code:
alias correct_numbers {
  ; returns the amount of correct numbers
  ; usage: $correct_sumbers(1 2 4 5 6 8, 1 5 6 7 8 9)
  ; would return 4 matches: 1 5 6 8
  var %i = $numtok($1,32), %matches = 0, %mn
  while (%i) {
    if ($istok($2,$gettok($1,%i,32),32)) {
      var %mn = $addtok(%mn,$gettok($1,%i,32),32)
      inc %matches
    }
    dec %i
  }
  return %matches matches: $sorttok(%mn,32,n)
}

Joined: Jun 2005
Posts: 44
B
BNX Offline OP
Ameglian cow
OP Offline
Ameglian cow
B
Joined: Jun 2005
Posts: 44
Thanks a bunch.

I havn't had much experience with tokens so I would of never thought of that. But that chkall() identifier idea would pwn wouldnt it? :tongue:
Or atleast arrays.

Last edited by BNX; 30/07/05 10:09 AM.
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Since you said this was a match of 6 against 6 and while you didnt say it since there lotto numbers none of the 6 should be the same in either set, but might be the same across sets.

$iif(($numtok($addtok($addtok($addtok($addtok($addtok($addtok(%var.1 %var.2 %var.3 %var.4 %var.5 %var.6,%iable.1,32),%iable.2,32),%iable.3,32),%iable.4,32),%iable.5,32),%iable.6,32),32) == 12),$false,$true)

comes out with $false if no match found, else $true

Simply uses the princible that $addtok wont add an existing token, thus reducing the total tokens below 12

------

If it can have duplicate values in the set, or the set is of flexable size then try this...

Code:
;usage $compare.var.lists(variablename1,number in group 1,variablename2,number in group 2)
;
; NB: when defining variablename1 & 2 do NOT include the %, ie %var1 %var2 %var3 then variablenameN would be "var"
;
;return $true  : match found
;       $false : no match found
;
; * limitations, The variables may not contain the $chr(13) as this is used as the token seperator *
;
alias compare.var.lists {
  var %i = $2, %group1 | while (%i) { var -s %group1 = $addtok(%group1,$($+(%,$1,%i),2),13) | dec %i }
  var %i = $4, %group2 | while (%i) { var -s %group2 = $addtok(%group2,$($+(%,$3,%i),2),13) | dec %i }
  tokenize 13 %group1 | scon -r if ($istok(%group2, $* ,13)) return $TRUE
  return $FALSE
}


In your case it would be
$compare.var.lists(var. , 6 , iable. , 6 )

I make the first group into a string, then the second group also, next i tokenize the first group into $1-, and then using the scon and $* command i check if any one of group1 is in group2, returning $true if they are, else it finishes and returns $false

Joined: Jun 2005
Posts: 44
B
BNX Offline OP
Ameglian cow
OP Offline
Ameglian cow
B
Joined: Jun 2005
Posts: 44
I cant have duplicate values, but I have another 'if' that checks it.
Kelder's script works great, but I appreciate your alteration.

Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Quote:
I cant have duplicate values, but I have another 'if' that checks it.
Kelder's script works great, but I appreciate your alteration.


Wellif it cant have dups then the below is gonna out perform anything short of a regex I would say.

if ( $iif(($numtok($addtok($addtok($addtok($addtok($addtok($addtok(%var.1 %var.2 %var.3 %var.4 %var.5 %var.6,%iable.1,32),%iable.2,32),%iable.3,32),%iable.4,32),%iable.5,32),%iable.6,32),32) == 12),$false,$true) ) { ... one matched so do something ... }

Joined: Feb 2004
Posts: 206
D
Fjord artisan
Offline
Fjord artisan
D
Joined: Feb 2004
Posts: 206
Thinking on my feet ....

$calc( 12 - $numtok($addtok($addtok($addtok($addtok($addtok($addtok(%var.1 %var.2 %var.3 %var.4 %var.5 %var.6,%iable.1,32),%iable.2,32),%iable.3,32),%iable.4,32),%iable.5,32),%iable.6,32),32))

will give you the number of matches so ..
Code:
 
var %num_matches = $calc( 12 - $numtok($addtok($addtok($addtok($addtok($addtok($addtok(%var.1 %var.2 %var.3 %var.4 %var.5 %var.6,%iable.1,32),%iable.2,32),%iable.3,32),%iable.4,32),%iable.5,32),%iable.6,32),32))

if (%num_matches > 4 ) { splay "Im_in_the_money.wav" }
elseif (%num_matches = 3 ) {some other action }
 


Again, not tested.

Cheers,

DK


Darwin_Koala

Junior Brat, In-no-cent(r)(tm) and original source of DK-itis!

Link Copied to Clipboard