elixir_prime_table v0.1.0 Primes

Utility functions for working with prime numbers

Summary

Functions

Returns the first N prime numbers

Returns a 2D list of primes

Returns the nth prime number

Returns true if the number is prime, false otherwise

Functions

first(n)
first(pos_integer) :: list

Returns the first N prime numbers.

Examples

iex> Primes.first(3) |> Enum.to_list
[2, 3, 5]
multiplication_table(n)
multiplication_table(pos_integer) :: [list]

Returns a 2D list of primes.

Examples

iex> Primes.multiplication_table(3)
[ [ 0,  2,  3,  5 ],
  [ 2,  4,  6, 10 ],
  [ 3,  6,  9, 15 ],
  [ 5, 10, 15, 25 ] ]
prime(n)
prime(pos_integer) :: pos_integer

Returns the nth prime number.

Examples

iex> Primes.prime(3)
5

iex> Primes.prime(10000)
104_729

iex> Primes.prime(-5)
** (ArgumentError) not a positive integer
prime?(n)
prime?(number) :: boolean

Returns true if the number is prime, false otherwise.

Examples

iex> Primes.prime? 1
false

iex> Primes.prime? 2
true

iex> Primes.prime? 3
true

iex> Primes.prime? 5
true

iex> Primes.prime? 6
false

iex> Primes.prime? 7
true

iex> Primes.prime? 11
true

iex> Primes.prime? 23
true

iex> Primes.prime? 42
false

iex> Primes.prime? 104729
true

iex> Primes.prime? -3
false