factorial 0.1.3 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +7 -4
- data/README.rdoc +5 -1
- data/bin/lcm +7 -0
- data/lib/factorial.rb +3 -6
- data/lib/factorial/lcm.rb +30 -0
- metadata +5 -3
data/README.md
CHANGED
@@ -3,7 +3,7 @@ Factorial
|
|
3
3
|
|
4
4
|
Description
|
5
5
|
------------
|
6
|
-
Factorial helps you to calculate the factorial of a number
|
6
|
+
Factorial helps you to calculate the factorial of a number or a list of numbers. e.g factorial of 5 = 120. It has also the features to find the greatest common factor (GCF) of the series of numbers and the least common factor (LCM).
|
7
7
|
|
8
8
|
Requirements
|
9
9
|
------------
|
@@ -24,10 +24,13 @@ Usage
|
|
24
24
|
|
25
25
|
### For determining the factorial of a number
|
26
26
|
|
27
|
-
|
27
|
+
result = Factorial::Base.new(numbers) e.g 2, 5
|
28
28
|
|
29
|
-
|
29
|
+
result.factorial_result => 2, 120
|
30
30
|
|
31
31
|
### For determining the GCF
|
32
32
|
|
33
|
-
|
33
|
+
result.gcf_result => 1
|
34
|
+
|
35
|
+
### For determining the LCM
|
36
|
+
result.lcm_result => 10
|
data/README.rdoc
CHANGED
@@ -3,7 +3,7 @@ Factorial
|
|
3
3
|
|
4
4
|
Description
|
5
5
|
------------
|
6
|
-
Factorial helps you to calculate the factorial of a number or a list of numbers. e.g factorial of 5 = 120. It has also the features to find the greatest common factor (GCF) of the series of numbers.
|
6
|
+
Factorial helps you to calculate the factorial of a number or a list of numbers. e.g factorial of 5 = 120. It has also the features to find the greatest common factor (GCF) of the series of numbers and the Least Common Factor (LCM).
|
7
7
|
|
8
8
|
Requirements
|
9
9
|
------------
|
@@ -32,4 +32,8 @@ Usage
|
|
32
32
|
|
33
33
|
fact.gcf_result => 1
|
34
34
|
|
35
|
+
### For determining the LCM
|
36
|
+
|
37
|
+
fact.lcm_result => 10
|
38
|
+
|
35
39
|
|
data/bin/lcm
ADDED
data/lib/factorial.rb
CHANGED
@@ -1,19 +1,16 @@
|
|
1
1
|
require 'factorial/result'
|
2
2
|
require 'factorial/gcf'
|
3
|
+
require 'factorial/lcm'
|
3
4
|
|
4
5
|
module Factorial
|
5
6
|
|
6
7
|
class Base
|
7
|
-
attr_reader :factorial_result, :gcf_result
|
8
|
+
attr_reader :factorial_result, :gcf_result, :lcm_result
|
8
9
|
|
9
10
|
def initialize(*args)
|
10
11
|
@factorial_result = Factorial::Result.new(*args)
|
11
12
|
@gcf_result = Factorial::Gcf.new(*args)
|
13
|
+
@lcm_result = Factorial::Lcm.new(*args)
|
12
14
|
end
|
13
|
-
|
14
|
-
def greatest_common_factor
|
15
|
-
@gcf = Factorial::Gcf.new(*args)
|
16
|
-
end
|
17
|
-
|
18
15
|
end
|
19
16
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'factorial/gcf'
|
2
|
+
|
3
|
+
module Factorial
|
4
|
+
class Lcm < Array
|
5
|
+
|
6
|
+
def initialize(*number_array)
|
7
|
+
@num_arr = *number_array
|
8
|
+
self << manage_the_array_for_lcm
|
9
|
+
end
|
10
|
+
|
11
|
+
def manage_the_array_for_lcm
|
12
|
+
lcm = 1
|
13
|
+
(0..@num_arr.length - 1).each do |i|
|
14
|
+
lcm = lcm_method(@num_arr[i], @num_arr[i + 1])
|
15
|
+
@num_arr[i + 1] = lcm
|
16
|
+
end
|
17
|
+
lcm
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
22
|
+
def lcm_method(n1, n2)
|
23
|
+
return n1 unless n2
|
24
|
+
gcd = Factorial::Gcf.new(n1, n2)
|
25
|
+
n1 = (n1 * n2) /gcd[0]
|
26
|
+
n1
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: factorial
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,9 +9,9 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-08-04 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
|
-
description:
|
14
|
+
description: It will calculate the factorial, GCF, LCM of the number
|
15
15
|
email: santattech@gmail.com
|
16
16
|
executables:
|
17
17
|
- factorial
|
@@ -21,10 +21,12 @@ files:
|
|
21
21
|
- lib/factorial.rb
|
22
22
|
- lib/factorial/result.rb
|
23
23
|
- lib/factorial/gcf.rb
|
24
|
+
- lib/factorial/lcm.rb
|
24
25
|
- spec/spec_helper.rb
|
25
26
|
- spec/factorial_spec.rb
|
26
27
|
- bin/factorial
|
27
28
|
- bin/gcf
|
29
|
+
- bin/lcm
|
28
30
|
- ./README.md
|
29
31
|
- ./README.rdoc
|
30
32
|
homepage: http://rubygems.org/gems/factorial
|