SieveOfEratosthenes (sieve_of_eratosthenes v0.1.1) View Source

Documentation for SieveOfEratosthenes. Implementation of sieve of eratosthenes algorithm to calculate all the prime numbers until number given used as limit, using tail recursive optimization and async functions

Link to this section Summary

Functions

Calculate all the primes until given input used as limit

Get the size of the chunk using the square root from input this number are used to limit the prime calculation using the sieve of eratosthenes algorithm

Generate a list between two and input number And chunk that list by the chunk_size

filter all non-multiple numbers of the given primes

Calculate all primes of list given using the sieve of eratosthenes algorithm

remove all the multiples numbers from given number list using list of prime numbers

Link to this section Functions

Calculate all the primes until given input used as limit

Get the size of the chunk using the square root from input this number are used to limit the prime calculation using the sieve of eratosthenes algorithm

Examples

iex> SieveOfEratosthenes.get_chunk_size(1_000)
32
Link to this function

get_chunked_list(input, chunk_size)

View Source

Generate a list between two and input number And chunk that list by the chunk_size

Examples

iex> SieveOfEratosthenes.get_chunked_list(10, 2)
[[2, 3], [4, 5], [6, 7], [8, 9], [10]]
Link to this function

get_non_multiples(numbers, primes)

View Source

filter all non-multiple numbers of the given primes

Examples

iex> SieveOfEratosthenes.get_non_multiples([2..100], [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]
Link to this function

recursive_primes(list, primes)

View Source

Calculate all primes of list given using the sieve of eratosthenes algorithm

Examples

iex> SieveOfEratosthenes.recursive_primes([2,3,4,5,6,7,8,9,10], [])
[2, 3, 5, 7]
Link to this function

remove_multiples(list, number_list)

View Source

remove all the multiples numbers from given number list using list of prime numbers

Examples

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