-- examples, generated by AI

local x = 10
local y = 20
local result = x + y * 2
print("Result:", result)

function fib(n)
    if n <= 1 then
        return n
    else
        return fib(n - 1) + fib(n - 2)
    end
end

-- Calculate fibonacci numbers
for i = 1, 10 do
    print("fib(" .. i .. ") =", fib(i))
end


function mandelbrot(c_real, c_imag, max_iter)
    local z_real = 0
    local z_imag = 0
    local iter = 0

    while iter < max_iter do
        local z_real_sq = z_real * z_real
        local z_imag_sq = z_imag * z_imag

        if z_real_sq + z_imag_sq > 4 then
            return iter
        end

        local new_z_real = z_real_sq - z_imag_sq + c_real
        local new_z_imag = 2 * z_real * z_imag + c_imag

        z_real = new_z_real
        z_imag = new_z_imag
        iter = iter + 1
    end

    return max_iter
end

local width = 20
local height = 20
local max_iter = 100

for y = 1, height do
    for x = 1, width do
        local c_real = (x - width / 2) * 4 / width
        local c_imag = (y - height / 2) * 4 / height

        local iterations = mandelbrot(c_real, c_imag, max_iter)

        if iterations == max_iter then
            print("*")
        else
            print(" ")
        end
    end
    print("\n")
end
