Skip to content
forked from ruby/prime

Prime numbers and factorization library.

License

Notifications You must be signed in to change notification settings

jeremyevans/prime

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Prime numbers and factorization library.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 99.4%
  • Shell 0.6%