Game Maker Games, Articles, Tutorials & More

Game Maker Network


Howdy, Guest! Please sign in or register an account.

Print

fibonacci

By Daniel · January 1, 2009

Computes the n'th number of the fibonacci sequence iteratively, taking O(n) time. This is accurate up to n=78.

/* fibonacci(n)
 *
 * Computes the n'th number of the fibonacci sequence iteratively, taking
 * O(n) time. This is accurate up to (and including) n=78.
 */

var f, i;

f[0] = 0; f[1] = 1;

for (i = 2; i <= argument0; i += 1)
  f[i] = f[i - 2] + f[i - 1];

return f[argument0];

Categories: Mathematics

Comments

There are no comments to display.

Post a Comment

You must be signed in to post comments.

Advertisement