Last active
May 8, 2016 06:52
-
-
Save vamdt/8208593 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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