lucas-numbers

This commit is contained in:
2024-03-07 07:33:20 -05:00
parent 5704073c97
commit b4e1570ba6
11 changed files with 383 additions and 0 deletions

View 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