(Translated by https://www.hiragana.jp/)
Module:Repeat symbols: Difference between revisions - Wikipedia Jump to content

Module:Repeat symbols: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Jackmcbarn (talk | contribs)
make this able to handle numbers of arbitrary size
Jackmcbarn (talk | contribs)
clarify error
Line 5: Line 5:
function p.main(frame)
function p.main(frame)
local n = tonumber(frame.args.n)
local n = tonumber(frame.args.n)
assert(n, 'The first argument must be a number')
assert(n, 'You must provide a number')
assert(n == math.floor(n), 'The number must be an integer')
assert(n == math.floor(n), 'The number must be an integer')
local digits, counts, outputs = {}, {}, {}
local digits, counts, outputs = {}, {}, {}

Revision as of 21:10, 16 September 2014

require('Module:No globals')

local p = {}

function p.main(frame)
	local n = tonumber(frame.args.n)
	assert(n, 'You must provide a number')
	assert(n == math.floor(n), 'The number must be an integer')
	local digits, counts, outputs = {}, {}, {}
	for k,v in ipairs(frame.args) do
		digits[k] = v
		counts[k] = n % 10^k
		n = (n - n % 10^k) / 10
	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[tail - k] = v:rep(counts[k])
	end
	return table.concat(outputs)
end

return p