Skip to content

abryrath/primex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Primex

This is an educational exercise with the following objectives:

  • Refactor and document someone else's code
  • Provide a usable primes generator, like ruby's Prime module

Original code comes from http://rosettacode.org/wiki/Sieve_of_Eratosthenes#Elixir

Installation

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

def deps do
  [
    {:primex, "~> 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/primex.

Usage

Currently, Primex provides 2 API functions:

Primex.stream/0

Get a Primes sieve stream

Examples

   iex> Primex.stream() |> Stream.take(25) |> Enum.to_list()
   [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]

   iex> Primex.stream() |> Stream.take_while(&(&1 < 100)) |> Enum.to_list()
   [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]

Primex.under/1

Get a stream of Primes under the given limit

Examples

   iex> Primex.under(100) |> Enum.to_list()
   [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]

Benchmarks

To run benchmarks with benchee, use mix benchmarks/main.exs

Benchmark Runtime Boxplot

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages