Fibonacci Sequence

Generate the first N numbers of the Fibonacci sequence where each number is the sum of the two preceding ones.

Code

Algorithms
fib = [0, 1]
(2...n).each { |i| fib << fib[i-1] + fib[i-2] }
fib.take(n)

Parameters

Number of Fibonacci numbers to generate

Server

More Ruby Snippets