Created
March 13, 2012 01:27
-
-
Save kyanny/2026028 to your computer and use it in GitHub Desktop.
Elixir fibonacci #1
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 end | |
def fib(1) do 1 end | |
def fib(n) do fib(n-1) + fib(n-2) end | |
end | |
IO.puts Fib.fib(10) |
Lawrence-2001
commented
Aug 1, 2023
•
defmodule Fib do
def run(a, b, n) do
case n do
1 ->
b
_ ->
run(b, a + b, n - 1)
end
end
end
Fib.run(0,1,10) |> IO.puts()
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment