jianyu/question.lua

24 lines
861 B
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

local Question = {}
-- randomseed 已经在主程序里被设定,我们无需设定
-- TODO换一个占用空间更小的方式来存储题目及答案目前有点太大了
Question.question_set = require "packages/jianyu/questions/init"
-- 随机返回一个问题
---@return any[] @ 返回一个列表其中第一个是问题String第二个是答案列表第三个是正确答案String
Question.getRandomQuestion = function()
local paper_index = math.random(#Question.question_set)
local question_index = math.random(#Question.question_set[paper_index])
local question = Question.question_set[paper_index][question_index]
return question
end
Question.questionCount = function()
local count = 0
for _, i in ipairs(Question.question_set) do
count = count + #i
end
return #Question.question_set, count
end
return Question