Skip to content

Instantly share code, notes, and snippets.

@v-kolesnikov
Created October 29, 2016 21:36
Show Gist options
  • Select an option

  • Save v-kolesnikov/b2610dfca9cdfeafce19613547630573 to your computer and use it in GitHub Desktop.

Select an option

Save v-kolesnikov/b2610dfca9cdfeafce19613547630573 to your computer and use it in GitHub Desktop.
Решето Эратосфена.
def nth(n) when n < 2, do: [n]
def nth(n), do: Prime.iter((for x <- 2..n, do: x), [])
def iter([], primes), do: primes
def iter([x | xs], s) do
xs
|> Enum.filter(fn(n) -> rem(n, x) != 0 end)
|> Prime.iter([x | s])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment