You are currently viewing the GMLscripts.com static mirror. Forum access and script submissions are not available through this mirror.

Invert GMLscripts.com

fibonacci

Returns the nth number of the Fibonacci sequence.

Wikipedia:

In mathematics, the Fibonacci numbers, commonly denoted \(F_n\) , form a sequence, the Fibonacci sequence, in which each number is the sum of the two preceding ones. The sequence commonly starts from 0 and 1, although some authors omit the initial terms and start the sequence from 1 and 1 or from 1 and 2. Starting from 0 and 1, the next few values in the sequence are:

\(0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ...\)

fibonacci(n)
Returns the nth number of the Fibonacci sequence.
COPY/// @func   fibonacci(n)
///
/// @desc   Returns the nth number of the Fibonacci sequence.
///
/// @param  {real}      n           desired number, non-negative integer
///
/// @return {real}      nth Fibonacci number
///
/// GMLscripts.com/license

function fibonacci(n)
{
    return round(power((1 + sqrt(5)) / 2, n) / sqrt(5));
}

Contributors: xot

GitHub: View · Commits · Blame · Raw