Created
October 29, 2016 21:36
-
-
Save v-kolesnikov/b2610dfca9cdfeafce19613547630573 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 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