--------------------------------------24H制定时器
local function setTimer(hour, minute, interval)---时,分,提示检测
while true do
local currentTime = os.date("*t")
if currentTime.hour >= hour and currentTime.min >= minute then
break
else
local remainingTimeSeconds = (hour * 3600 + minute * 60) - (currentTime.hour * 3600 + currentTime.min * 60 + currentTime.sec)
if remainingTimeSeconds >= 60 then
local 剩余分钟=remainingTimeSeconds / 60
剩余分钟=math.ceil(剩余分钟)
print(剩余分钟.."分钟后执行")
else
print(string.format("%d 秒后执行...", remainingTimeSeconds))
end
os.execute("sleep "..interval)
end
end
print("当前时间已到达定时时间")
end
setTimer(16, 30, 5)
--------------------------------------时间定时器
function tim_定时器(tim_f)---tim_f为分钟定时
local 定时=math.modf(tim_f*60/5)
local wb_js=0
print("定时器已开启")
for i=1,定时 do
local hs=定时-i
if hs<=12 then--剩余时间不足1分钟每隔5S提示一次剩余时间
local tim_s=i*5
print("剩余时间:"..定时*5-tim_s.."S")
else
local 剩余分钟=math.modf(定时*5/60)
if wb_js >= 6 or wb_js==0 then ---剩余时间大于1分钟每隔30S提示一次剩余时间,首次调用提示一次
print("剩余分钟:"..剩余分钟.."分钟")
wb_js=0
end
wb_js=wb_js+1
end
sleep(5000)
end
print("定时器结束")
return true
end
--------------------------------------冒泡算法排序
function bub(arr)
local len = #arr
for i = 1, len - 1 do
for j = 1, len - i do
if arr[j] > arr[j + 1] then
arr[j], arr[j + 1] = arr[j + 1], arr[j]
end
end
end
end
local array = {3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5}
bub(array)
print(array)
print(table.concat(array, "<"))
--------------------------------------懒人快速排序算法
function quickSort(arr, low, high)
if low < high then
local pivotIndex = partition(arr, low, high)
quickSort(arr, low, pivotIndex - 1)
quickSort(arr, pivotIndex + 1, high)
end
end
function partition(arr, low, high)
local pivot = arr[high]
local i = low - 1
for j = low, high - 1 do
if arr[j] <= pivot then
i = i + 1
arr, arr[j] = arr[j], arr
end
end
arr[i + 1], arr[high] = arr[high], arr[i + 1]
return i + 1
end
local arr = {3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5}
quickSort(arr, 1, #arr)
print(table.concat(arr, ", "))
--------------------------------------仅供参考,如有写的不对的地方请多多指导,使用了就留下你的足迹吧~
---龙腾
|