「モジュール:テスト2」の版間の差分

ナビゲーションに移動 検索に移動
編集の要約なし
編集の要約なし
編集の要約なし
1行目: 1行目:
local p={}
local p={}


function p.test(frame)
function p.listTurples(frame)
local a = 2
local ansTyp = frame.args[1]
local c = a and assert("a is true.")
local ans = assert(tonumber(frame.args[2]), "答えを半角数字で指定してください。")
return c
local arr = {}
local t = 3
while frame.args[t] do
arr[t-2] = frame.args[t]
t = t + 1
end
local output = ""
if ansTyp == "sum"then
for i = 1, #arr - 2 do
for j = i + 1, #arr - 1 do
if i ~= j then
local rest = ans - i - j
for k = j + 1, #arr do
if arr[k] == rest then
output = output.."("..arr[i]..","..arr[j]..","..rest..")"
end
end
end
end
end
if output == "" then return "指定された条件に適する組はありません。" end
return output
elseif ansTyp == "product" then
for i = 1, #arr - 2 do
for j = i + 1, #arr - 1 do
if i ~= j then
if ans % (i * j) == 0 then
rest = ans % (i * j)
for k = j + 1, #arr do
if arr[k] == rest then
output = output.."("..arr[i]..","..arr[j]..","..rest..")"
end
end
end
end
end
end
if output == "" then return "指定された条件に適する組はありません。" end
return output
else
error("答えの種類を適切に指定してください")
end
end
end


return p
return p
3,283

回編集

案内メニュー