This gem provides you a set of minimal utility functions to manage prime numbers.
-
0.0.3:
- Renames .prime_serie into .enumerator.
- Adds .serie class method.
-
0.0.2: Fix .prime_serie.
-
0.0.1: initial release. It provides just these class functions:
nth_prime(n)
: retun the nth prime number.enumerator
: return an enumerator over the prime serie.
Add this line to your application's Gemfile:
gem 'eratostene_sieve'
And then execute:
$ bundle
Or install it yourself as:
$ gem install eratostene_sieve
Just require eratostene_sieve wherever you want to user a function it provides:
require 'eratostene_sieve'
Then call the function you like in your code:
# nth_prime(n) example
EratosterneSieve.nth_prime(10) # => 29
# enumerator example
enumerator = EratosteneSieve.enumerator
serie = []
(0..9).each { |i| serie << enumerator.next }
puts serie # => [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
# serie example
serie = EratosteneSieve.serie(:from => 1, :up_to => 10)
puts serie # => [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
- Fork it ( http://github.com//eratostene_sieve/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request