Prime numbers and factorization library.
Clone or download
stomar and hsbt default gems: add missing comment in gemspec
* lib/csv/csv.gemspec: [DOC] add comment for require fallback
  in Ruby repository.

* lib/logger.gemspec: ditto.
* lib/prime.gemspec: ditto.
* lib/rexml/rexml.gemspec: ditto.
* lib/rss/rss.gemspec: ditto.
* lib/webrick/webrick.gemspec: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65037 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Latest commit d2c807b Oct 12, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin bundle gem prime Jun 2, 2018
lib remove unused methods Jun 23, 2018
test add testcases of prime library Jun 23, 2018
.gitignore Ignore Gemfile.lock Jun 2, 2018
.travis.yml Enabled Travis CI Jun 2, 2018
Gemfile bundle gem prime Jun 2, 2018
LICENSE.txt Update license: MIT to BSD-2-Clause Jun 2, 2018
README.md update readme Jul 6, 2018
Rakefile Enabled test suite with rake task. Jun 2, 2018
prime.gemspec default gems: add missing comment in gemspec Oct 20, 2018

README.md

Prime

Prime numbers and factorization library.

Installation

Add this line to your application's Gemfile:

gem 'prime'

And then execute:

$ bundle

Or install it yourself as:

$ gem install prime

Usage

require 'prime'

# Prime is the set of all prime numbers, and it is Enumerable.
Prime.take(4)             #=> [2, 3, 5, 7]
Prime.first(4)            #=> [2, 3, 5, 7]
Prime.each(7).to_a        #=> [2, 3, 5, 7]

# Determining whether an arbitrary integer is a prime number
Prime.prime?(7)           #=> true
8.prime?                  #=> false

# Factorization in prime numbers
Prime.prime_division(779)                           #=> [[19, 1], [41, 1]]
Prime.int_from_prime_division([[19, 1], [41, 1]])   #=> 779

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/prime.

License

The gem is available as open source under the terms of the BSD-2-Clause.