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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3a7bdad3ee832e67e60f81b058983001b616a6c9
4
- data.tar.gz: 4c7b07dc511d2281bd3abe4109b86b570533d4e1
3
+ metadata.gz: e135a6e685d9c1924db601d4b2120bc09063f5e1
4
+ data.tar.gz: ab25aa59e62189c58102e1f30ec924f29731af3e
5
5
  SHA512:
6
- metadata.gz: 91ee88368dd92c311b6beec7ebc9036dc76b711b229f8296c2c6d1b9ede210cf5d55767566787b49a5a550c0a1020437d381f95bac6cd851bac2b02d9c01ef21
7
- data.tar.gz: 16150e3d61bdaa74a17cab523972d4bb67e29aa6dc0f0507afb8d75088e7dc78e566929a005b827089225a3c4b435864eb5d4b5305db68db7edd10b911bebaab
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module RMathPlus
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -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
 
@@ -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.1
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-05 00:00:00.000000000 Z
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.2.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.