Compute Fibonacci
Examples
Filter
def fibonacci( n )
return n if ( 0..1 ).include? n
( fibonacci( n - 1 ) + fibonacci( n - 2 ) )
end
puts fibonacci( 5 )
fun main() {
println(fibonacci(10))
}
fun fibonacci(n: Int): Long {
if (n == 0) return 0
if (n == 1) return 1
return fibonacci(n - 1) + fibonacci(n - 2)
}
function fibonacci(n)
if n<3 then
return 1
else
return fibonacci(n-1) + fibonacci(n-2)
end
end
for n = 1, 16 do
io.write(fibonacci(n), ", ")
end
io.write("...\n")