r_math_plus 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -0
- data/lib/r_math_plus.rb +23 -0
- data/lib/r_math_plus/version.rb +1 -1
- data/r_math_plus.gemspec +1 -1
- data/spec/r_math_plus_spec.rb +11 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e135a6e685d9c1924db601d4b2120bc09063f5e1
|
4
|
+
data.tar.gz: ab25aa59e62189c58102e1f30ec924f29731af3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b37745cdd3d90342f551862fb83d1ec010bbd476741c73b75069e729314b9768e63d52248ed26f8509e56cb1b0aca06b9053396880d07f06cb253582ec82767
|
7
|
+
data.tar.gz: f77f7ef336ca69e30e6514be34fcaf97246c27e5b826d721d342af3ecbe70885005d85841cb39d60806d9dcb217134a0712e0ae80caeee4f0f0113292e4e4b4d
|
data/README.md
CHANGED
@@ -43,6 +43,11 @@ The '.prime_array' method takes an integer as a parameter and returns an array w
|
|
43
43
|
RMathPlus.prime_array(10) # => [2,3,5,7]
|
44
44
|
```
|
45
45
|
|
46
|
+
'.nth_prime' returns the first 'n' primes passed as a parameter to the method:
|
47
|
+
```ruby
|
48
|
+
RMathPlus.nth_prime(3) # => [2,3,5]
|
49
|
+
```
|
50
|
+
|
46
51
|
'.prime_factors' returns an array of the prime factors of a given number n. If n is a prime, it will return n.
|
47
52
|
Ex:
|
48
53
|
```ruby
|
data/lib/r_math_plus.rb
CHANGED
@@ -35,6 +35,29 @@ module RMathPlus
|
|
35
35
|
return prime_array
|
36
36
|
end
|
37
37
|
|
38
|
+
def self.nth_prime(n) #returns an array with all primes less than number n.
|
39
|
+
if n <= 1
|
40
|
+
if n == 1
|
41
|
+
return [2]
|
42
|
+
end
|
43
|
+
if n < 1
|
44
|
+
raise "Wops, there's no 0th prime!"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
prime_array = [2]
|
48
|
+
i = 2
|
49
|
+
array_size = 1 # compares faster than running prime_array.size on each loop
|
50
|
+
while true
|
51
|
+
i += 1
|
52
|
+
if RMathPlus.is_prime?(i,prime_array) # the own prime_array built so far is passed as an argument in order to improve processing speed.
|
53
|
+
prime_array.push(i)
|
54
|
+
array_size += 1
|
55
|
+
break if array_size == n
|
56
|
+
end
|
57
|
+
end
|
58
|
+
return prime_array
|
59
|
+
end
|
60
|
+
|
38
61
|
def self.prime_factors(number, biggest_number_prime_array=false) #returns the prime factors of a given number. if n is prime, returns n. second parameter to improve speed if method would be utilized in a range of numbers.
|
39
62
|
factors = []
|
40
63
|
if biggest_number_prime_array
|
data/lib/r_math_plus/version.rb
CHANGED
data/r_math_plus.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Otávio Monteagudo"]
|
10
10
|
spec.email = ["oivatom@gmail.com"]
|
11
11
|
spec.summary = %q{ Math operations to use in puzzles. }
|
12
|
-
spec.description = %q{ Some extra math ops to the standard library which include prime number operations and the least common multiple of an array of numbers. }
|
12
|
+
spec.description = %q{ Some extra math ops to the standard library which include prime number operations and the least common multiple of an array of numbers. See the Documentation link below for further details.}
|
13
13
|
spec.homepage = "https://github.com/otamm/RMathPlus"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
data/spec/r_math_plus_spec.rb
CHANGED
@@ -42,6 +42,17 @@ describe RMathPlus do
|
|
42
42
|
|
43
43
|
end
|
44
44
|
|
45
|
+
describe ".nth_prime" do
|
46
|
+
|
47
|
+
it "returns an array with the first n primes" do
|
48
|
+
expect(RMathPlus.nth_prime(3)).to eq [2,3,5]
|
49
|
+
end
|
50
|
+
|
51
|
+
it "returns first prime if n == 1" do
|
52
|
+
expect(RMathPlus.nth_prime(1)).to eq [2]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
45
56
|
describe ".prime_factors" do
|
46
57
|
|
47
58
|
it "returns repeated prime factors of a given number" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: r_math_plus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Otávio Monteagudo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -53,7 +53,8 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 3.0.0
|
55
55
|
description: " Some extra math ops to the standard library which include prime number
|
56
|
-
operations and the least common multiple of an array of numbers.
|
56
|
+
operations and the least common multiple of an array of numbers. See the Documentation
|
57
|
+
link below for further details."
|
57
58
|
email:
|
58
59
|
- oivatom@gmail.com
|
59
60
|
executables: []
|
@@ -91,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
92
|
version: '0'
|
92
93
|
requirements: []
|
93
94
|
rubyforge_project:
|
94
|
-
rubygems_version: 2.
|
95
|
+
rubygems_version: 2.4.6
|
95
96
|
signing_key:
|
96
97
|
specification_version: 4
|
97
98
|
summary: Math operations to use in puzzles.
|