Skip to content

Instantly share code, notes, and snippets.

@tacitphoenix
Created August 18, 2016 20:11
Show Gist options
  • Save tacitphoenix/83c40ffed4b075c66b3bf67a61b97eba to your computer and use it in GitHub Desktop.
Save tacitphoenix/83c40ffed4b075c66b3bf67a61b97eba to your computer and use it in GitHub Desktop.
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