lucas-numbers
This commit is contained in:
17
elixir/lucas-numbers/lib/lucas_numbers.ex
Normal file
17
elixir/lucas-numbers/lib/lucas_numbers.ex
Normal file
@@ -0,0 +1,17 @@
|
||||
defmodule LucasNumbers do
|
||||
@moduledoc """
|
||||
Lucas numbers are an infinite sequence of numbers which build progressively
|
||||
which hold a strong correlation to the golden ratio (φ or ϕ)
|
||||
|
||||
E.g.: 2, 1, 3, 4, 7, 11, 18, 29, ...
|
||||
"""
|
||||
|
||||
def generate(count) when is_integer(count) and count > 0 do
|
||||
{2, 1}
|
||||
|> Stream.iterate(fn {a, b} -> {b, a + b} end)
|
||||
|> Stream.map(&elem(&1, 0))
|
||||
|> Enum.take(count)
|
||||
end
|
||||
|
||||
def generate(_count), do: raise(ArgumentError, "count must be specified as an integer >= 1")
|
||||
end
|
||||
Reference in New Issue
Block a user