Tutorialspoint

Execute Lua Online

local c1 = 0
local c2 = 0
local c3 = 0
local c4 = 0
local c5 = 0
local c6 = 0
local c7 = 0
local trials = 1
math.randomseed(os.time())
for c = 1, trials do
    local b1 = false
    local b2 = false
    local b3 = false
    local b4 = false
    local b5 = false
    local b6 = false
    local b7 = false
    local lc = 0
    while b1 ~= true and b2 ~= true and b3 ~= true and b4 ~= true and b5 ~= true and b6 ~= true and b7 ~= true do
        local r = math.random(127)
        if r <= 1 then
            if b7 == false then
                b7 = true
                if lc > c7 then
                    c7 = lc
                end
            end
        end
        if r > 1 and r <= 3 then
            if b6 == false then
                b6 = true
                if lc > c6 then
                    c6 = lc
                end
            end
        end
        if r > 3 and r <= 7 then
            if b5 == false then
                b5 = true
                if lc > c5 then
                    c5 = lc
                end
            end
        end
        if r > 7 and r <= 15 then
            if b4 == false then
                b4 = true
                if lc > c4 then
                    c4 = lc
                end
            end
        end
        if r > 15 and r <= 31 then 
            if b3 == false then
                b3 = true
                if lc > c3 then
                    c3 = lc
                end
            end
        end
        if r > 31 and r <= 63 then 
            if b2 == false then
                b2 = true
                if lc > c2 then
                    c2 = lc
                end
            end
        end
        if r > 63 and r <= 127 then 
            if b1 == false then
                b1 = true
                if lc > c1 then
                    c1 = lc
                end
            end
        end
        lc = lc + 1
    end
end
print(c1)
print(c2)
print(c3)
print(c4)
print(c5)
print(c6)
print(c7)

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.