Add several elixir solutions
This commit is contained in:
1 parent
57bc7b0289
commit
56734c60b9
32 files changed
+1191
No files matched your search
@@ -0,0 +1,18 @@
|
||||
defmodule LucasNumbers do
|
||||
defguardp is_positive(k) when is_integer(k) and k > 0
|
||||
@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(1), do: [2]
|
||||
def generate(2), do: [2, 1]
|
||||
def generate(count) when is_positive(count) do
|
||||
Stream.iterate({2,1}, fn {x,y} -> {y, x+y} end)
|
||||
|> Stream.map(fn {x,_} -> x end)
|
||||
|> Enum.take(count)
|
||||
end
|
||||
|
||||
def generate(_), do: raise ArgumentError, "count must be specified as an integer >= 1"
|
||||
end
|
||||
Reference in new issue
Block a user