Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- alias nre { return -?((\d|\x2C)+?(!|\.\d+?)?(x|y)?|\.\d+?(x|y)?) }
- alias mnre { return (x|y|pi|(?-i)e|(?-i)G| $+ $nre $+ (t(ril)?|b(il)?|m(il)?|k)?) }
- alias mcre { return (\+|-|\*|\/|\^|\%) }
- alias mathre {
- var %x
- .fopen formula txt/formula.txt
- while ($fread(formula)) {
- %x = $addtok(%x,$gettok($v1,1,9),124)
- }
- .fclose formula
- return ( $+ %x $+ )
- }
- 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):#:{
- 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))
- var %x = $1-, %r
- if ($count($1-,$chr(40)) != $count($1-,$chr(41))) || ($count($1-,$chr(91)) != $count($1-,$chr(93))) {
- msg $chan Invalid input: Mismatched brackets.
- return
- }
- else {
- if ($regex(range,%x,/x\sfrom\s(\d{1,3})\sto\s(\d{1,3})/ix)) {
- var %n = $regml(range,1), %m = $regml(range,2), %t
- while (%n <= %m) {
- %i = %x
- while ($regex(var,%i,/(?<![a-z])(x|y)(?!\s?(\=|from))/i)) {
- %i = $regsubex(%i,/((?<![a-z]) $regml(var,1) (?!\s?(\=|from)))/igx,%n)
- }
- %t = $addtok(%t, $chr(32) $bytes($calc(%i),bd) $chr(32),45)
- inc %n
- }
- msg $chan %t
- return
- }
- else {
- while ($regex(var,%x,/(?<![a-z])(x|y)(?!\s?\=)/i)) {
- if (!$regex(%x,/ $regml(var,1) \=/ix)) {
- msg $chan solving isnt done yet
- return
- }
- noop $regex(r,%x,/ $regml(var,1) \=(-?\d+(\.\d+)?|\.\d+)/igx)
- %x = $regsubex(%x,/((?<![a-z]) $regml(var,1) (?!\=))/igx,$regml(r,1))
- }
- }
- }
- while ($chr(91) isin %x) { %x = $regsubex(%x,/([a-z]+\[[^\[|\]]+\])/i,$mfunc(\1)) }
- if ($regex(%x,/\sbase\s?([1-9]|[1-2][0-9]|[3][0-6])$/)) { msg $chan $base($calc(%x),10,$regml(1)) }
- else { msg $chan $bytes($calc(%x),bd) }
- }
- 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):#:{
- if ($count($1-,$chr(40)) != $count($1-,$chr(41))) || ($count($1-,$chr(91)) != $count($1-,$chr(93))) { msg $chan Invalid input: Mismatched brackets. }
- elseif ($2 == remove) {
- if ($read(txt/formula.txt,w,$3 $+ *)) {
- write -ds $+ $3 txt/formula.txt
- msg $chan Formula $qt($3) removed.
- }
- else { msg $chan Formula $qt($3) doesn't exist. }
- }
- elseif (!$read(txt/formula.txt,w,$2 $+ *)) {
- write txt/formula.txt $2 $chr(9) $3-
- msg $chan Formula $qt($2) added.
- }
- else { msg $chan Formula $qt($2) already exists. }
- }
- alias mfunc {
- noop $regex($1-,/^([a-z]+)\[(.+?)\]$/gi)
- var %n = $regml(1), %c = $calc($regml(2))
- .fopen mfunc txt/formula.txt
- while ($fread(mfunc)) {
- var %x = $v1, %r = $gettok(%x,1,9), %f = $gettok(%x,2,9)
- if ($regex(%n,/^( %r )/ix)) { break }
- }
- .fclose mfunc
- %f = $calc($($regsubex(%f,/X/ig,%c),3))
- return %f
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement