Module:Sandbox/TheTruthCreator/Sample1

From Wikipedia, the free encyclopedia
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