编辑代码

-- https://www.twle.cn/l/yufei/exercise/python-exercise-1.html
function a1()
    for i = 1, 4 do
        for j = 1, 4 do 
            for k = 1, 4 do
                if (i ~= j and i ~=k and j ~= k) then
                    print(i .. j .. k)
                end
            end
        end
    end
end



function p3()
    local res, go; res = 1; go = true;
    while (not isSq(res + 100) or (not isSq(res + 100 + 168))) do
        res = res + 1
    end
    print(res)
    return res
end

function isSq(n)
    local i; i = 1
    while (i * i ~= n and i < n) do i = i + 1 end
    return i < n
end

function p4(y, m, d)
    function isLeap(y)
        if (y % 400 == 0) then return true
        elseif (y % 100 == 0) then return false
        elseif (y % 4 ==0) then return true
        else return false end
    end
    local res, xs; res = 0; xs = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
    for i = 1, m - 1 do res = res + xs[i] end -- NOTE it's m - 1
    res = res + d 
    if (isLeap(y)) then res = res + 1 end
    print(res)
    return res
end

p4(2015, 6, 7)