Make sure you have Node version > 6
I recommend using CRNA to build ReactNative apps.
defmodule Prime do | |
@moduledoc """ | |
A number 'n' is prime only when it is not divisible by any number between 2 and √n | |
""" | |
def run(2), do: true | |
def run(num) when num > 2 and rem(num, 2) != 0 do | |
is_prime(3, num, round(:math.sqrt(num) + 1)) | |
end | |
def run(_), do: false |
defmodule Factorial do | |
@moduledoc """ | |
Factorial for a given non-negative number | |
""" | |
def run(0), do: 1 | |
def run(num) when num > 0 do | |
Enum.reduce 1..num, 1, &(&1 * &2) | |
end | |
def run(_), do: nil | |
end |
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: ") |
Prettier
with your editor.