Created
December 8, 2014 06:44
-
-
Save andremedeiros/21a31d0b6fae0c8b62f0 to your computer and use it in GitHub Desktop.
This file contains 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(0), do: 0 | |
def fib(1), do: 1 | |
def fib(2), do: 1 | |
def fib(n), do: fib(n, 1, 1) | |
defp fib(3, prev, cur), do: prev + cur | |
defp fib(n, prev, cur), do: fib(n - 1, cur, prev + cur) | |
end | |
IO.puts Fib.fib(1000000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment