Skip to content

Instantly share code, notes, and snippets.

@paulanthonywilson
Created August 12, 2015 12:58
Show Gist options
  • Save paulanthonywilson/27f1b5744a29abb12737 to your computer and use it in GitHub Desktop.
Save paulanthonywilson/27f1b5744a29abb12737 to your computer and use it in GitHub Desktop.
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