Skip to content

Instantly share code, notes, and snippets.

@MikaelFangel
Created November 26, 2024 13:19
Show Gist options
  • Save MikaelFangel/1b7776a9e3f292e0bf050ce971a18611 to your computer and use it in GitHub Desktop.
Save MikaelFangel/1b7776a9e3f292e0bf050ce971a18611 to your computer and use it in GitHub Desktop.
Tailcall optimized fibonacci in Elixir
defmodule Fibonacci do
def fibonacci(n) when n >= 0, do: fibonacci(n, 0, 1)
defp fibonacci(0, current, _next), do: current
defp fibonacci(n, current, next), do: fibonacci(n - 1, next, current + next)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment