Skip to content

Instantly share code, notes, and snippets.

@pulkit110
Last active September 30, 2021 08:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pulkit110/1c477da9e47dbc5fdb6df582b7999e59 to your computer and use it in GitHub Desktop.
Save pulkit110/1c477da9e47dbc5fdb6df582b7999e59 to your computer and use it in GitHub Desktop.
Fibonacci Number Generator in Elixir
defmodule Fib do
def number(n) do
cache =
2..n
|> Enum.reduce(%{prev: 0, current: 1}, fn _i, acc ->
%{prev: acc.current, current: acc.prev + acc.current}
end)
|> Map.get(:current)
end
end
Fib.number(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment