Advertisement
Flip

Calc script

Jun 9th, 2012
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 2.71 KB | None | 0 0
  1. alias nre { return -?((\d|\x2C)+?(!|\.\d+?)?(x|y)?|\.\d+?(x|y)?) }
  2. alias mnre { return (x|y|pi|(?-i)e|(?-i)G| $+ $nre $+ (t(ril)?|b(il)?|m(il)?|k)?) }
  3. alias mcre { return (\+|-|\*|\/|\^|\%) }
  4. alias mathre {
  5.   var %x
  6.   .fopen formula txt/formula.txt
  7.   while ($fread(formula)) {
  8.     %x = $addtok(%x,$gettok($v1,1,9),124)
  9.   }
  10.   .fclose formula
  11.   return ( $+ %x $+ )
  12. }
  13. on $*:text:$(/^(\x28*( $mathre \x5B)*\x28* $mnre \x5D*(\s? $mcre \s?\x28*( $mathre \x5B)*\x28* $mnre (\x5D|\x29)*)+?|( $mathre \x5B) $mnre \x5D*)(\sbase\s?([1-9]|[1-2][0-9]|[3][0-6]))?(\x2C?\s(x|y|z)\s?\=\s? $nre |\s?\=\s?-?((\d|\x2C)+?(!|\.\d+?)?|\.\d+?))*$/ix):#:{
  14.   tokenize 32 $numconv($.replace($regsubex($regsubex($1-,/(\d+)(\!)/g,factorial[ $+ \1 $+ ]),/(\d)(x|y|z)/ig,\1 * \2),/pi/g,$pi,/(?<=^|\W|\+|-|\*|\/|\^|\%)e/g,2.71828182845904523536,/(?<=^|\W|\+|-|\*|\/|\^|\%)G/g,0.915965594177219015054,$chr(44),$null))
  15.   var %x = $1-, %r
  16.   if ($count($1-,$chr(40)) != $count($1-,$chr(41))) || ($count($1-,$chr(91)) != $count($1-,$chr(93))) {
  17.     msg $chan Invalid input: Mismatched brackets.
  18.     return
  19.   }
  20.   else {
  21.     while ($regex(var,%x,/(?<![a-z])(x|y)(?!\s?\=)/i)) {
  22.       if (!$regex(%x,/ $regml(var,1) \=/ix)) {
  23.         msg $chan solving isnt done yet
  24.         return
  25.       }
  26.       noop $regex(r,%x,/ $regml(var,1) \=(\d+(\.\d+)?|\.\d+)/igx)
  27.       %x = $regsubex(%x,/((?<![a-z]) $regml(var,1) (?!\=))/igx,$regml(r,1))
  28.     }
  29.   }
  30.   while ($chr(91) isin %x) { %x = $regsubex(%x,/([a-z]+\[[^\[|\]]+\])/i,$mfunc(\1)) }
  31.   if ($regex(%x,/\sbase\s?([1-9]|[1-2][0-9]|[3][0-6])$/)) { msg $chan $base($calc(%x),10,$regml(1)) }
  32.   else { msg $chan $bytes($calc(%x),bd) }
  33. }
  34. on $*:text:$(/^formula\s(remove\s([a-z]+\d?)|([a-z]+\d?)\s(\x28*-?(\d+?(!|\.\d+?)?x?|\.\d+?x?|x|pi|(?-i)e|(?-i)G)(\s?(\+|-|\*|\/|\^|\%)\s?\x28*-?(\d+?(!|\.\d+?)?x?|\.\d+?x?|x|pi|(?-i)e|(?-i)G)\x29*)+?))$/i):#:{
  35.   if ($count($1-,$chr(40)) != $count($1-,$chr(41))) || ($count($1-,$chr(91)) != $count($1-,$chr(93))) { msg $chan Invalid input: Mismatched brackets. }
  36.   elseif ($2 == remove) {
  37.     if ($read(txt/formula.txt,w,$3 $+ *)) {
  38.       write -ds $+ $3 txt/formula.txt
  39.       msg $chan Formula $3 removed.
  40.     }
  41.     else { msg $chan Formula $3 doesn't exist. }
  42.   }
  43.   elseif (!$read(txt/formula.txt,w,$2 $+ *)) {
  44.     write txt/formula.txt $2 $chr(9) $3-
  45.     msg $chan Formula $2 added.
  46.   }
  47.   else { msg $chan Formula $2 already exists. }
  48. }
  49. alias mfunc {
  50.   noop $regex($1-,/^([a-z]+)\[(.+?)\]$/gi)
  51.   var %n = $regml(1), %c = $calc($regml(2))
  52.   .fopen mfunc txt/formula.txt
  53.   while ($fread(mfunc)) {
  54.     var %x = $v1, %r = $gettok(%x,1,9), %f = $gettok(%x,2,9)
  55.     if ($regex(%n,/^( %r )/ix)) { break }
  56.   }
  57.   .fclose mfunc
  58.   %f = $calc($($regsubex(%f,/X/ig,%c),3))
  59.   return %f
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement