Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/oleander/is_prime
Is the given number a prime number?
https://github.com/oleander/is_prime
Last synced: about 2 months ago
JSON representation
Is the given number a prime number?
- Host: GitHub
- URL: https://github.com/oleander/is_prime
- Owner: oleander
- Created: 2011-05-16T21:30:09.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2011-05-16T21:31:18.000Z (over 13 years ago)
- Last Synced: 2024-03-14T13:02:51.685Z (10 months ago)
- Language: Ruby
- Homepage: https://github.com/oleander/is_prime
- Size: 89.8 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# is_prime
Is the given number a prime number?
Follow me on [Twitter](http://twitter.com/linusoleander) or [Github](https://github.com/oleander/) for more info and updates.
## How to use
```` ruby
require "is_prime"3.prime? # => true
4.prime? # => false
````## What algorithm is being used?
The implementation is just one line.
```` ruby
('1' * N) !~ /^1?$|^(11+?)\1+$/
````Read more about it [here](http://www.noulakaz.net/weblog/2007/03/18/a-regular-expression-to-check-for-prime-numbers/).
## How to install
[sudo] gem install is_prime
## Requirements
*is_prime* is tested in Mac OS X 10.6.6, 10.6.7 using Ruby 1.8.7, 1.9.2.
## License
*is_prime* is released under the *MIT license*.