summaryrefslogtreecommitdiff
path: root/c-luajit/fibonacci.lua
blob: e52eb07b5ec4f89f41d361f6367c7ed308c9db9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
-- Naive recursive implementation to increase the time of computation.
function fibonacci(n)
    if n == 0 then
        return 0
    elseif n == 1 then
        return 1
    else
        return fibonacci(n - 1) + fibonacci(n - 2)
    end
end

local n = 40
local result = fibonacci(n)
print("The " .. n .. "th Fibonacci number is: " .. result)