Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function IsPrime(numb) if numb<=1 or numb%2==0 then return false; end for n = 2, numb^(1/2) do if numb % n == 0 then return false; end end return true; end
- local function StringToNumber(str)
- if tonumber(str)~=nil then
- return tonumber(str);
- end
- str = tostring(str):lower();
- local number = 0;
- for n=1,str:len() do
- number = number + str:byte(n);
- end
- return number;
- end
- return function(msg,usr,chan)
- if msg==nil or msg=="" then
- msg = usr;
- end
- local numb = StringToNumber(msg);
- if IsPrime(numb) then
- print("@"..usr.." " .. msg .. " (".. numb ..") is a prime number");
- else
- print("@"..usr.." " .. msg .. " (".. numb ..") is NOT a prime number");
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement