Skip to content

Repository files navigation

Prime

CI

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 numberPrime.prime?(7)#=> true8.prime?#=> false# Factorization in prime numbersPrime.prime_division(8959)#=> [[17, 2], [31, 1]]Prime.int_from_prime_division([[17,2],[31,1]])#=> 895917**2 * 31#=> 8959

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.

Topics

Resources

Security policy

Stars

39 stars

Watchers

33 watching

Forks

Releases

Packages

Used by

Contributors

Languages