Advertisement
Flip

Untitled

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