Sieve of Atkin

Elixir CIstandard-readme compliant

Generates prime numbers using the Sieve of Atkin algorithm.

The Sieve of Atkin is a modern algorithm for finding prime numbers that has better asymptotic complexity than the ancient Sieve of Eratosthenes. The Sieve of Eratosthenes has a time complexity of O(n log log n), whereas the Sieve of Atkin has a time complexity of O(n). That means the Sieve of Atkin will take twice as much time to compute twice as many primes.

This library was also designed to utilize as much CPU as is available, thanks to Elixir's wonderful concurrency tools as well as the Flow library.

Installation

If available in Hex, the package can be installed by adding sieve_of_atkin to your list of dependencies in mix.exs:

def deps do
  [
    {:sieve_of_atkin, "~> 0.1.0"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/sieve_of_atkin.

Usage

This project defines only one module with one function: SieveOfAtkin.generate_primes/1. It generates prime numbers up to a given limit.

SieveOfAtkin.generate_primes(30) |> Enum.sort() == [
  2, 3, 5, 7, 11, 13, 17, 19, 23, 29
]

Maintainer

This project was developed by Rosa Richter. You can get in touch with her on Keybase.io.

Contributing

Questions and pull requests are more than welcome. I follow Elixir's tenet of bad documentation being a bug, so if anything is unclear, please file an issue! Ideally, my answer to your question will be in an update to the docs.

License

MIT License

Copyright 2020 Rosa Richter

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.