Last active
August 11, 2016 17:55
-
-
Save wende/1060a14b9e8680bbe73c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def n_primes(n), do: prime(n, 2) | |
def is_prime(x), do: (2..x |> Enum.filter(fn a -> rem(x, a) == 0 end) |> length()) == 1 | |
def prime(n, n), do: [] | |
def prime(n, acc) do | |
case is_prime(acc) do | |
true -> [acc | prime(n, acc + 1)] | |
false -> prime(n, acc + 1) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment