Skip to content

Instantly share code, notes, and snippets.

@radik909
Last active November 20, 2022 12:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save radik909/82788b16fe0e1a00c25ccbf85b7c0574 to your computer and use it in GitHub Desktop.
Save radik909/82788b16fe0e1a00c25ccbf85b7c0574 to your computer and use it in GitHub Desktop.
Find first n fibonacci numbers (using Stream in Elixir)
defmodule Fibonacci do
def run(num) when num > 0 do
Stream.unfold({1, 1}, fn {a, b} ->
{a, {b, a + b}}
end)
|> Enum.take(num)
end
end
IO.gets("Enter the limit: ")
|> String.strip
|> String.to_integer
|> Fibonacci.run
|> IO.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment