Skip to content

Instantly share code, notes, and snippets.

@vamdt vamdt/fibonacci.exs
Last active May 8, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.