Advertisement
Flip

Untitled

Feb 22nd, 2017
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 3.23 KB | None | 0 0
  1.  
  2. alias nre { return -?((\d|\x2C)+?(!|\.\d+?)?(x|y)?|\.\d+?(x|y)?) }
  3. alias mnre { return (-?x|-?y|-?pi|(?-i)e|(?-i)G| $+ $nre $+ (t(ril)?|b(il)?|m(il)?|k)?) }
  4. alias mcre { return (\+|-|\*|\/|\^|\%) }
  5. alias mathre {
  6.   var %x
  7.   .fopen formula txt/formula.txt
  8.   while ($fread(formula)) {
  9.     %x = $addtok(%x,$gettok($v1,1,9),124)
  10.   }
  11.   .fclose formula
  12.   return ( $+ %x $+ )
  13. }
  14. 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 |x\sfrom\s-?\d{1,3}\sto\s\d{1,3}))*$/ix):#:{
  15.   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))
  16.   var %x = $1-, %r
  17.   if ($count($1-,$chr(40)) != $count($1-,$chr(41))) || ($count($1-,$chr(91)) != $count($1-,$chr(93))) {
  18.     msg $chan Invalid input: Mismatched brackets.
  19.     return
  20.   }
  21.   else {
  22.     if ($regex(range,%x,/x\sfrom\s(-?\d{1,3})\sto\s(\d{1,3})/ix)) {
  23.       var %n = $regml(range,1), %m = $regml(range,2), %t
  24.       while (%n <= %m) {
  25.         %i = %x
  26.         while ($regex(var,%i,/(?<![a-z])(x|y)(?!\s?(\=|from))/i)) {
  27.           %i = $regsubex(%i,/((?<![a-z]) $regml(var,1) (?!\s?(\=|from)))/igx,%n)
  28.         }
  29.         %t = $addtok(%t, $chr(32) $bytes($calc(%i),bd) $chr(32),45)
  30.         inc %n
  31.       }
  32.       msg $chan %t
  33.       return
  34.     }
  35.     else {
  36.       while ($regex(var,%x,/(?<![a-z])(x|y)(?!\s?\=)/i)) {
  37.         if (!$regex(%x,/ $regml(var,1) \=/ix)) {
  38.           msg $chan solving isnt done yet
  39.           return
  40.         }
  41.         noop $regex(r,%x,/ $regml(var,1) \=(-?\d+(\.\d+)?|\.\d+)/igx)
  42.         %x = $regsubex(%x,/((?<![a-z]) $regml(var,1) (?!\=))/igx,$regml(r,1))
  43.       }
  44.     }
  45.   }
  46.   while ($chr(91) isin %x) { %x = $regsubex(%x,/([a-z]+\[[^\[|\]]+\])/i,$mfunc(\1)) }
  47.   if ($regex(%x,/\sbase\s?([1-9]|[1-2][0-9]|[3][0-6])$/)) { msg $chan $base($calc(%x),10,$regml(1)) }
  48.   else { msg $chan $bytes($calc(%x),bd) }
  49. }
  50. 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):#:{
  51.   if ($count($1-,$chr(40)) != $count($1-,$chr(41))) || ($count($1-,$chr(91)) != $count($1-,$chr(93))) { msg $chan Invalid input: Mismatched brackets. }
  52.   elseif ($2 == remove) {
  53.     if ($read(txt/formula.txt,w,$3 $+ *)) {
  54.       write -ds $+ $3 txt/formula.txt
  55.       msg $chan Formula $qt($3) removed.
  56.     }
  57.     else { msg $chan Formula $qt($3) doesn't exist. }
  58.   }
  59.   elseif (!$read(txt/formula.txt,w,$2 $+ *)) {
  60.     write txt/formula.txt $2 $chr(9) $3-
  61.     msg $chan Formula $qt($2) added.
  62.   }
  63.   else { msg $chan Formula $qt($2) already exists. }
  64. }
  65. alias mfunc {
  66.   noop $regex($1-,/^([a-z]+)\[(.+?)\]$/gi)
  67.   var %n = $regml(1), %c = $calc($regml(2))
  68.   .fopen mfunc txt/formula.txt
  69.   while ($fread(mfunc)) {
  70.     var %x = $v1, %r = $gettok(%x,1,9), %f = $gettok(%x,2,9)
  71.     if ($regex(%n,/^( %r )/ix)) { break }
  72.   }
  73.   .fclose mfunc
  74.   %f = $calc($($regsubex(%f,/X/ig,%c),3))
  75.   return %f
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement