https://github.com/ruby/prime
Prime numbers and factorization library.
https://github.com/ruby/prime
ruby
Last synced: about 1 month ago
JSON representation
Prime numbers and factorization library.
- Host: GitHub
- URL: https://github.com/ruby/prime
- Owner: ruby
- License: other
- Created: 2018-02-22T10:57:14.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2025-02-18T01:36:03.000Z (4 months ago)
- Last Synced: 2025-03-31T21:48:10.989Z (3 months ago)
- Topics: ruby
- Language: Ruby
- Homepage:
- Size: 151 KB
- Stars: 36
- Watchers: 34
- Forks: 18
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: COPYING
Awesome Lists containing this project
README
# Prime
[](https://github.com/ruby/prime/actions/workflows/test.yml)
Prime numbers and factorization library.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'prime'
```And then execute:
$ bundle
Or install it yourself as:
$ gem install prime
## Usage
```ruby
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(8959) #=> [[17, 2], [31, 1]]
Prime.int_from_prime_division([[17, 2], [31, 1]]) #=> 8959
17**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](LICENSE.txt).