is_prime 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.rspec +5 -0
- data/Gemfile +4 -0
- data/README.md +36 -0
- data/Rakefile +2 -0
- data/is_prime.gemspec +27 -0
- data/lib/is_prime.rb +5 -0
- data/lib/is_prime/version.rb +3 -0
- data/spec/is_prime_spec.rb +17 -0
- data/spec/spec_helper.rb +9 -0
- metadata +77 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# is_prime
|
2
|
+
|
3
|
+
Is the given number a prime number?
|
4
|
+
|
5
|
+
Follow me on [Twitter](http://twitter.com/linusoleander) or [Github](https://github.com/oleander/) for more info and updates.
|
6
|
+
|
7
|
+
## How to use
|
8
|
+
|
9
|
+
```` ruby
|
10
|
+
require "is_prime"
|
11
|
+
|
12
|
+
3.prime? # => true
|
13
|
+
4.prime? # => false
|
14
|
+
````
|
15
|
+
|
16
|
+
## What algorithm is being used?
|
17
|
+
|
18
|
+
The implementation is just one line.
|
19
|
+
|
20
|
+
```` ruby
|
21
|
+
('1' * N) !~ /^1?$|^(11+?)\1+$/
|
22
|
+
````
|
23
|
+
|
24
|
+
Read more about it [here](http://www.noulakaz.net/weblog/2007/03/18/a-regular-expression-to-check-for-prime-numbers/).
|
25
|
+
|
26
|
+
## How to install
|
27
|
+
|
28
|
+
[sudo] gem install is_prime
|
29
|
+
|
30
|
+
## Requirements
|
31
|
+
|
32
|
+
*is_prime* is tested in Mac OS X 10.6.6, 10.6.7 using Ruby 1.8.7, 1.9.2.
|
33
|
+
|
34
|
+
## License
|
35
|
+
|
36
|
+
*is_prime* is released under the *MIT license*.
|
data/Rakefile
ADDED
data/is_prime.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "is_prime/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "is_prime"
|
7
|
+
s.version = IsPrime::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Linus Oleander"]
|
10
|
+
s.email = ["linus@oleander.nu"]
|
11
|
+
s.homepage = "https://github.com/Oleander/is_prime"
|
12
|
+
s.summary = %q{Is the given number a prime number?}
|
13
|
+
s.description = %q{
|
14
|
+
Is the given number a prime number?
|
15
|
+
3.prime? # => true
|
16
|
+
4.prime? # => false
|
17
|
+
}
|
18
|
+
|
19
|
+
s.rubyforge_project = "is_prime"
|
20
|
+
|
21
|
+
s.files = `git ls-files`.split("\n")
|
22
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
23
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
24
|
+
s.require_paths = ["lib"]
|
25
|
+
|
26
|
+
s.add_development_dependency("rspec", "2.5.0")
|
27
|
+
end
|
data/lib/is_prime.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "is_prime"
|
2
|
+
|
3
|
+
describe "Fixnum#prime?" do
|
4
|
+
it "should know what a prime number is" do
|
5
|
+
numbers = %w{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97}
|
6
|
+
numbers.each do |num|
|
7
|
+
num.to_i.should be_prime
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should not be a prime number" do
|
12
|
+
4.should_not be_prime
|
13
|
+
1.should_not be_prime
|
14
|
+
0.should_not be_prime
|
15
|
+
-1.should_not be_prime
|
16
|
+
end
|
17
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: is_prime
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Linus Oleander
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-05-16 00:00:00 +02:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: rspec
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - "="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 2.5.0
|
25
|
+
type: :development
|
26
|
+
version_requirements: *id001
|
27
|
+
description: "\n Is the given number a prime number?\n 3.prime? # => true\n 4.prime? # => false\n "
|
28
|
+
email:
|
29
|
+
- linus@oleander.nu
|
30
|
+
executables: []
|
31
|
+
|
32
|
+
extensions: []
|
33
|
+
|
34
|
+
extra_rdoc_files: []
|
35
|
+
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- .rspec
|
39
|
+
- Gemfile
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- is_prime.gemspec
|
43
|
+
- lib/is_prime.rb
|
44
|
+
- lib/is_prime/version.rb
|
45
|
+
- spec/is_prime_spec.rb
|
46
|
+
- spec/spec_helper.rb
|
47
|
+
has_rdoc: true
|
48
|
+
homepage: https://github.com/Oleander/is_prime
|
49
|
+
licenses: []
|
50
|
+
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "0"
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
requirements: []
|
69
|
+
|
70
|
+
rubyforge_project: is_prime
|
71
|
+
rubygems_version: 1.6.2
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: Is the given number a prime number?
|
75
|
+
test_files:
|
76
|
+
- spec/is_prime_spec.rb
|
77
|
+
- spec/spec_helper.rb
|