adding_multiples 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/adding_multiples-0.1.2.gem +0 -0
- data/adding_multiples-0.1.3.gem +0 -0
- data/lib/adding_multiples/CLI.rb +40 -13
- data/lib/adding_multiples/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b1d72002add177a4222beedcdb24ae22c74efeb30a1c87b4906cbed84268fdf
|
4
|
+
data.tar.gz: f19f98117bf407b211447f47693117630e63909b0ab7a2b006730551290b629a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d436ba8f937c6d88c5a60836bd16a43f493863457372d958673febf43ff572958577a1bca6e6683cb9c020016a3b27101d8e52b18029da41bcf67d7aae69cf31
|
7
|
+
data.tar.gz: 35a53fab0e2620646b76c9ed84d14a56e4ce6f3b20696c07e0d9a4aadcecde3d7a2b90b82dd08b0ce3830241344ab2d6c401bc4c95217cd86ce087a2e3d1d876
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# AddingMultiples
|
2
2
|
|
3
|
-
Thank you for checking out my gem! The purpose of this gem is to
|
3
|
+
Thank you for checking out my gem! The purpose of this gem is to answer the following information: `Find the sum of all multiples of 3 or 5 less than 1000`.
|
4
4
|
|
5
|
-
However,
|
5
|
+
However, users can input any two numbers the wish.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
Binary file
|
Binary file
|
data/lib/adding_multiples/CLI.rb
CHANGED
@@ -40,34 +40,33 @@ module AddingMultiples
|
|
40
40
|
# ask user for another integer
|
41
41
|
def get_another_integer
|
42
42
|
input = ""
|
43
|
-
puts "\
|
44
|
-
|
45
|
-
while input != "y" && input != "n"
|
46
|
-
puts "Please enter 'y' or 'n'"
|
47
|
-
input = gets.strip.downcase
|
48
|
-
end
|
43
|
+
puts "\nPlease enter another positive integer:"
|
44
|
+
@integer << gets.strip
|
49
45
|
|
50
|
-
if
|
51
|
-
|
46
|
+
if @integer[@i].match(/\d+/)
|
47
|
+
sum_integer_multiples
|
52
48
|
else
|
53
|
-
|
54
|
-
end
|
49
|
+
get_another_integer
|
50
|
+
end
|
55
51
|
end
|
56
52
|
|
57
|
-
|
58
53
|
#loop through multiples and compare to range [1-1000], consider allowing user input for range
|
59
|
-
def
|
54
|
+
def sum_integer_multiples
|
60
55
|
@range = [1, 1000]
|
61
|
-
@multiple = 0
|
62
56
|
@sum = 0
|
63
57
|
|
64
58
|
@integer.each do |i|
|
65
59
|
integer = i.to_i
|
60
|
+
@multiple = 0
|
66
61
|
while @multiple < @range[1]
|
67
62
|
calculate_sum
|
68
63
|
@multiple += integer
|
69
64
|
end
|
70
65
|
end
|
66
|
+
|
67
|
+
# sum common multiples and subtract from total
|
68
|
+
sum_common_multiples
|
69
|
+
subtract_common_multiples
|
71
70
|
|
72
71
|
puts "The sum of the multiples of the integers #{@integer} that are less than #{@range[1]} is #{@sum}"
|
73
72
|
|
@@ -76,7 +75,35 @@ module AddingMultiples
|
|
76
75
|
# add multiples to sum
|
77
76
|
def calculate_sum
|
78
77
|
@sum += @multiple
|
78
|
+
end
|
79
|
+
|
80
|
+
# sum common multiples
|
81
|
+
def sum_common_multiples
|
82
|
+
@range = [1, 1000]
|
83
|
+
@least_common_multiple = 15
|
84
|
+
@common_multiples_sum = 0
|
85
|
+
@multiple = 0
|
86
|
+
|
87
|
+
|
88
|
+
while @multiple < @range[1]
|
89
|
+
@common_multiples_sum += @multiple
|
90
|
+
@multiple += @least_common_multiple
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
#calculate least common multiple
|
95
|
+
def calculate_least_common_multiple
|
96
|
+
integer_0 = @integer[0].to_i
|
97
|
+
integer_1 = @integer[1].to_i
|
98
|
+
@least_common_multiple = integer_0 * integer_1
|
99
|
+
|
79
100
|
end
|
101
|
+
|
102
|
+
# subtract common multiples
|
103
|
+
def subtract_common_multiples
|
104
|
+
@sum -= @common_multiples_sum
|
105
|
+
end
|
106
|
+
|
80
107
|
|
81
108
|
end
|
82
109
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adding_multiples
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- dicksonca
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-03-
|
11
|
+
date: 2019-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -86,6 +86,8 @@ files:
|
|
86
86
|
- Rakefile
|
87
87
|
- adding_multiples-0.1.0.gem
|
88
88
|
- adding_multiples-0.1.1.gem
|
89
|
+
- adding_multiples-0.1.2.gem
|
90
|
+
- adding_multiples-0.1.3.gem
|
89
91
|
- adding_multiples.gemspec
|
90
92
|
- bin/adding_multiples
|
91
93
|
- bin/console
|