Created
August 18, 2016 20:11
-
-
Save tacitphoenix/83c40ffed4b075c66b3bf67a61b97eba 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
defmodule Prime do | |
def run(n), do: Stream.iterate(1, &(&1 + 1)) |> Stream.filter(&(filter(&1))) |> Enum.take(n) | |
def filter(n) when n < 4, do: true | |
def filter(n), do: Enum.map(2..div(n,2), &(not(rem(n,&1) == 0))) |> Enum.all? | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment