Skip to content

Instantly share code, notes, and snippets.

@vamdt
Last active May 8, 2016 06:52
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save vamdt/8208593 to your computer and use it in GitHub Desktop.
defmodule Fib do
def fib(n) when n < 2 do
n
end
def fib(n) when n >= 2 do
fib(n-1) + fib(n-2)
end
end
function fibonacci (num) {
if (num === 1 || num === 2) {
return 1;
}
var temp =0, last1 = last2 = 1;
for (var i=3; i<=num; i++) {
temp = last1+last2;
last2 = last1;
last1 = temp;
}
return last1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment