Created
August 12, 2015 12:58
-
-
Save paulanthonywilson/27f1b5744a29abb12737 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 seq(n) when n >= 0, do: reverse_seq(n, [0], 1) |> Enum.reverse | |
defp reverse_seq(0, sequence, _next), do: sequence | |
defp reverse_seq(n, sequence = [last | _], next) do | |
reverse_seq(n - 1, [next | sequence], next + last) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment