Well i made a small SLOW snippet that you can calculate the least common multiple
Before the Comma are the numbers that you want to find the least common multiple
After the comma is the number that stands for the multiples that the script will search
//echo -a $ekp(4 6 8 12 16 48,20)
6 Numbers to Compare
in 20 Multiples Each.
Result: Least Common Multiple: 48
Changes:
Version 2: Code rewritten. Optimized. x100 Fastest
Version 1: Warning if the number after comma is bigger than 20, and there is no common multiple your mIRC will freeze for some seconds...
;;;;VERSION 2 Optimized!
;;;;VERSION 2 Optimized!
;;;;VERSION 2 Optimized!
alias ekp {
unset %ekp.*
var %i = 1
while (%i <= $numtok($1,32) ) {
var %z = 1
while (%z <= $2 ) {
set %ekp. $+ $gettok($1,%i,32) %ekp. [ $+ [ $gettok($1,%i,32) ] ] $calc($gettok($1,%i,32) * %z)
inc %z
}
inc %i
}
var %k = 1
var %z
while (%k <= $2) {
var %p = 0
var %i = 1
while (%i <= $numtok($1,32) ) {
if ($istokcs(%ekp. [ $+ [ $gettok($1,%i,32) ] ],$gettok(%ekp. [ $+ [ $gettok($1,1,32) ] ],%k,32),32)) {
inc %p
var %z = $gettok(%ekp. [ $+ [ $gettok($1,1,32) ] ],%k,32)
}
inc %i
}
if (%p == $numtok($1,32)) { return %z }
inc %k
}
}
;;;;VERSION 1
;;;;VERSION 1
;;;;VERSION 1
;;;;VERSION 1 Do Not Use, Only for the Records...
;;;;VERSION 1 Do Not Use, Only for the Records...
;;;;VERSION 1 Do Not Use, Only for the Records...
;;;;VERSION 1
;;;;VERSION 1
;;;;VERSION 1
alias ekp {
unset %ekp.*
var %i = 1
while (%i <= $numtok($1,32) ) {
var %z = 1
while (%z <= $2 ) {
set %ekp. $+ $gettok($1,%i,32) %ekp. [ $+ [ $gettok($1,%i,32) ] ] $calc($gettok($1,%i,32) * %z)
inc %z
}
inc %i
}
var %i = 1
while (%i <= $numtok($1,32) ) {
var %k = 1
while (%k <= $2) {
var %z = 1
var %p = 0
while (%z <= $2 ) {
var %a = 1
while (%a <= $numtok($1,32) ) {
if (%a != %i) {
if ( $gettok(%ekp. [ $+ [ $gettok($1,%i,32) ] ],%k,32) == $gettok(%ekp. [ $+ [ $gettok($1,%a,32) ] ],%z,32) ) { inc %p }
}
inc %a
}
if (%p == $calc($numtok($1,32) - 1)) { return Least Multiple Common: $gettok(%ekp. [ $+ [ $gettok($1,%i,32) ] ],%k,32) | halt }
inc %z
}
inc %k
}
inc %i
}
}
not quite optimized since you're still calling $gettok() and $numtok() many more times than necessary - set them to local variables if you're sure their values won't change across multiple calls. not to mention the method is slow in and of itself :P
a quick method for calculating the LCM of a list of integers is to note that LCM(a, b, c, ...) = LCM(LCM(a, b), c, ...), and that LCM(a, b) = a * b / GCD(a, b) where GCD() is the greatest common divisor and can be found using a very simple algorithm:
alias gcd {
while ($2) tokenize 32 $2 $calc($1 % $2)
return $1
}
then $lcm() can be defined as:
alias lcm {
var %i = 2, %lcm = $gettok($1, 1, 32)
while ($gettok($1, %i, 32) != $null) {
%lcm = $lcm_($v1, %lcm)
inc %i
}
return %lcm
}
alias lcm_ {
return $calc($1 * $2 / $gcd($1, $2))
}
where $lcm_() calculates the LCM of a pair of integers.
this is much more optimal and even lets you do away with requiring a value for $2, which shouldn't be necessary.
I had heard of a Whilefix.dll awhile back that was used on what seemed to be an mp3 snippet. Might be worth taking a look at; although I don't know that a small snippet such as this would be suffice motivation to download it. Apparently it prevents mIRC from freezing or 'hanging' in large while loops, and judging from the mass of while functions I'd say it could be of use.
EDIT: Found it. Check the description for the link. http://www.hawkee.com/snippet/8521/
Warning if the number after comma is bigger than 20, and there is no common multiple your mIRC will free for some seconds... You meant the word freeze
Usually a code that results in a hang or frozen state is not considered efficiently written; worse yet, it may give the users a bug-like experience. There has to be a better way to write a script like this.