Skip to content

Instantly share code, notes, and snippets.

@recluze
Forked from kyanny/fib.exs
Created August 18, 2018 16:05
Show Gist options
  • Save recluze/fd5bb0aa90c8fe5623c921172e83e975 to your computer and use it in GitHub Desktop.
Save recluze/fd5bb0aa90c8fe5623c921172e83e975 to your computer and use it in GitHub Desktop.
Elixir fibonacci #1
defmodule Fib do
def fib(0) do 0 end
def fib(1) do 1 end
def fib(n) do fib(n-1) + fib(n-2) end
end
IO.puts Fib.fib(10)
@recluze
Copy link
Author

recluze commented Aug 18, 2018

defmodule Fib do
  def fib(a, _, 0 ) do a end

  def fib(a, b, n) do fib(b, a+b, n-1) end

end
IO.puts Fib.fib(1,1,6)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment