Module:Sandbox/TheTruthCreator/Sample1: Difference between revisions
imported>TheTruthCreator No edit summary |
(No difference)
|
Latest revision as of 21:38, 11 July 2016
Documentation for this module may be created at Module:Sandbox/TheTruthCreator/Sample1/doc
local p={}
function p.toString(n)
local digits = {"0","1","2","3","4","5","6","7","8","9"}
local str = ""
while not (n == 0) do
local m = n % 10
str = digits[m + 1] .. str
n = (n - m) / 10
end
return str
end
function p.isPrime(num)
local prime = true
for i = 2 , (num - 1) , 1 do
if num%i == 0 then
prime = false
end
end
return prime
end
function p.test(frame)
local str = frame.args[1]
return str
end
function p.mersenne(frame)
local n = frame.args[1]
local str = ""
local m = 3
for i = 2 , n , 1 do
if p.isPrime(m) then
str = str .. p.toString(m)
if not (i == n) then
str = str .. " "
end
m = (m * 2) + 1
end
end
if str == "" then
str = "What the heck???"
end
return str
end
return p