Created
August 21, 2018 17:09
-
-
Save evantravers/58e616aa50a47eb1c113c8111fcd19d2 to your computer and use it in GitHub Desktop.
This file contains 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 sieve(n) when is_integer(n), do: sieve(Enum.to_list(2..n), [1]) | |
def sieve([], result), do: Enum.reverse(result) | |
def sieve([prime|tail], result) do | |
tail | |
|> Enum.reject(& rem(&1, prime) == 0) | |
|> sieve([prime|result]) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment