Jump to content

Module:Repeat symbols

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Erik Zachte (talk | contribs) at 14:17, 17 September 2014. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
require('Module:No globals')

local p = {}

function p.main(frame)
	local n = tonumber(frame.args.n)
	local d = tonumber(frame.args.d)
	assert(n, 'You must provide a number for arg1:n')
	assert(n == math.floor(n), 'arg1:n must be an integer')
	assert(d, 'You must provide a number for arg2:d')
	assert(d == math.floor(d), 'arg2:d must be an integer')
	local d = tonumber(frame.args.d)
	local digits, counts, outputs = {}, {}, {}
	for k,v in ipairs(frame.args) do
		digits[k] = v
		counts[k] = n % d^k
		n = (n - n % d^k) / d
	end
	assert(n == 0, 'The number cannot have more digits than there are pictures')
	local tail = #digits + 1
	for k,v in ipairs(digits) do
		outputs[k] = v:rep(counts[tail - k])
	end
	return table.concat(outputs)
end

return p