Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cb=peripheral.wrap("top")
- factorial=nil
- blacklist = {
- "tha_cre8er"
- }
- temp={}
- fibs={1,1}
- for i=1,186 do
- fibs[#fibs+1] = fibs[#fibs]+fibs[#fibs-1]
- end
- function checkNumb(tab)
- ok=true
- toR={}
- for k,v in pairs(tab) do
- s=tonumber(v)
- if not s then
- ok=false
- else
- toR[#toR+1] = tonumber(v)
- end
- end
- if ok then
- return toR
- else
- return false
- end
- end
- checknumb=checkNumb
- function factorial(n)
- n=tonumber(n)
- r=math.abs(n)
- d=1
- if r>34 then
- return "Infinity"
- else
- for y=1,r do
- d=d*y
- end
- if r==n then
- return d
- else
- return tonumber("-"..d)
- end
- end
- end
- function corParam(g,l)
- if type(g)==type({"a"}) then
- if#g==l then
- if checkNumb(g) then
- return true
- else
- return false
- end
- else
- return false
- end
- end
- end
- operations = {
- ["+"] = function(a)
- --print("+")
- if corParam(a,2) then
- ans = a[1]+a[2]
- return a[1].."+"..a[2].."="..ans
- else
- return "Incorrect parameters"
- end
- end,
- ["-"] = function(a)
- if corParam(a,2) then
- ans = a[1]-a[2]
- return a[1].."-"..a[2].."="..ans
- else
- return "Incorrect parameters"
- end
- end,
- ["/"] = function(a)
- if corParam(a,2) then
- ans = a[1]/a[2]
- return a[1].."/"..a[2].."="..ans
- else
- return "Incorrect parameters"
- end
- end,
- ["*"] = function(a)
- if corParam(a,2) then
- ans = a[1]*a[2]
- return a[1].."*"..a[2].."="..ans
- else
- return "Incorrect parameters"
- end
- end,
- ["sqrt"] = function(a)
- if corParam(a,1) then
- ans = math.sqrt(a[1])
- return "root("..a[1]..") = "..ans
- else
- return "Incorrect parameters"
- end
- end,
- ["root"] = function(a)
- if true then
- return operations["sqrt"](a)
- endfor i=1,10 do
- print(i)
- end
- end,
- ["!"] = function(a)
- if corParam(a,1) then
- ans=factorial(a[1])
- return a[1].."!".."="..ans
- else
- return "Incorrect parameters"
- end
- end,
- ["avg"] = function(a)
- if checkNumb(a) then
- if #a>0 then
- sum=0
- ou="avg("
- for ir=1,#a do
- sum=sum+a[ir]
- ou=ou..a[ir]..","
- end
- ou=string.sub(ou,1,#ou-1)..")"
- ans=sum/#a
- return ou.." = "..ans
- else
- return "Incorrect parameters"
- end
- else
- return "Incorrect parameters"
- end
- end,
- ["pi"] = function(a)
- pi="3.141592653789793238462643383279502884197169"
- if #a==0 then
- return "PI = "..pi
- elseif #a==1 and checkNumb(a) then
- return a[1].."PI = "..(tonumber(pi)*a[1])
- else
- return "Incorrect parameters"
- end
- end,
- ["sin"] = function(a)
- if corParam(a,1)then
- ans=math.sin(a[1])
- return "sin("..a[1]..") = "..ans
- else
- return "Incorrect parameters"
- end
- end,
- ["sine"] = function(a)
- if true then
- return operations["sin"](a)
- end
- end,
- ["triangle"] = function(a)
- if corParam(a,3) then
- temp.a=tonumber(a[1])
- temp.b=tonumber(a[2])
- temp.c=tonumber(a[3])
- if ((temp.a+temp.b>temp.c) and (temp.a+temp.c>temp.b) and (temp.b+temp.c>temp.a)) then
- temp.c1 = "True"
- else
- temp.c1 = "False"
- end
- return "tri("..temp.a..", "..temp.b..", "..temp.c..") = "..temp.c1
- else
- return "Incorrect parameters"
- end
- end,
- ["cos"] = function(a)
- if corParam(a,1) then
- ans=math.cos(a[1])
- return "cos("..a[1]..") = "..ans
- else
- return "Incorrect parameters"
- end
- end,
- ["fibonacci"] = function(a)
- if corParam(a,1) then
- a[1] = tonumber(a[1])
- if a[1]>0 and a[1]<189 then
- ans=fibs[tonumber(a[1])]
- return "fib("..a[1]..") = "..ans
- elseif a[1]>188 then
- return "Infinity"
- else
- return "Must input positive integer"
- end
- else
- return "Incorrect parameters"
- end
- end,
- ["rand"] = function(a)
- if corParam(a,2) then
- if a[1]<a[2] then
- math.randomseed(os.time()*1000)
- ans=math.random(a[1],a[2])
- return "rand("..a[1]..","..a[2]..") = "..ans
- else
- return "Interval is empty"
- end
- else
- return "Incorrect parameters"
- end
- end,
- ["random"] = function(a)
- if true then
- return operations["rand"](a)
- end
- end,
- ["degrees"] = function(a)
- if corParam(a,1) then
- ans=math.deg(a[1])
- return "rad("..a[1]..") = deg("..ans..")"
- else
- return "Incorrect parameters"
- end
- end,
- ["radians"] = function(a)
- if corParam(a,1) then
- ans=math.rad(a[1])
- return "deg("..a[1]..") = rad("..ans..")"
- else
- return "Incorrect parameters"
- end
- end,
- ["log"] = function(a)
- if corParam(a,2) then
- ans=math.log(a[2])/math.log(a[1])
- return "log("..a[2]..") in base "..a[1].." = "..ans
- else
- return "Incorrect parameters"
- end
- end,
- ["ln"] = function(a)
- if corParam(a,1) then
- ans=math.log(a[1])
- return "log("..a[1]..") in base e = "..ans
- end
- end,
- ["syntax"] = function(a)
- if true then
- return " Syntax: math:func:arg1:arg2..."
- end
- end,
- ["list"] = function(a)
- --print("list")
- --print(#a)
- if #a == 0 then
- ls=""
- --print("ls")
- for k,v in pairs(operations) do
- --print(#operations)
- if ls=="" then
- ls = k
- else
- ls=ls..", "..k
- end
- --print(ls)
- end
- return "Commands: "..ls
- else
- return "Incorrect parameters"
- end
- end
- }
- function parse(txt)
- colons = {}
- args={}
- for i=1,#txt do
- if string.sub(txt,i,i) == ":" then
- colons[#colons+1] = i
- end
- end
- for i=1,#colons-1 do
- args[#args+1] = string.sub(txt,colons[i]+1,colons[i+1]-1)
- end
- return args
- end
- while true do
- gf=true
- while gf do
- gf=false
- _,_,user,msg = os.pullEvent("chat_message")
- for k,v in pairs(blacklist) do
- if v==user then
- gf=true
- if #msg>4 then
- if string.sub(string.lower(msg),1,5) == ":math" then
- cb.tell(v,"You have been blacklisted")
- end
- end
- end
- end
- end
- msg=string.lower(msg)
- if string.sub(msg,1,1) == ":" then
- if string.sub(msg,#msg,#msg) == ":" then
- --nothing
- else
- msg=msg..":"
- end
- returned=parse(msg)
- if returned then
- if returned[1] == "math" then
- toGive={}
- for h=3,#returned do
- toGive[#toGive+1]=returned[h]
- end
- if operations[returned[2]] then
- if true then
- output=operations[returned[2]](toGive)
- cb.tell(user,output)
- end
- else
- if msg == ":math:" then
- cb.tell(user,operations["list"]({}))
- else
- cb.tell(user,"Incorrect function")
- end
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment