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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4d2895d5ba0bfe67cdc8b3bdbcdf8ca3270efcfed0b56e1614d4b5af5350ded5
4
- data.tar.gz: f1c5cdb768cbfa2b8746c7d7884f318b63821081889f849debd06b96ba311002
3
+ metadata.gz: 3b1d72002add177a4222beedcdb24ae22c74efeb30a1c87b4906cbed84268fdf
4
+ data.tar.gz: f19f98117bf407b211447f47693117630e63909b0ab7a2b006730551290b629a
5
5
  SHA512:
6
- metadata.gz: 87cab09178d22030890cab54c393b14ecb4862ea14e232ba8466019d4e59c67c4c33040a95e7e58b52e4b3313e2aff366bdf1e0e9a163fef53141b25a6d5de31
7
- data.tar.gz: b86e9c345d6c50d704d72e53c003bff5d793c813eac3f2b9a61c493bbac2b17ee1e501880dc93aaebc58861772fb22aaf3d793c3bc702dff3e6592cecfff828f
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 provide the following information: `Sum of all multiples of 3 or 5 less than 1000`.
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, I designed it to allow users to decide which positive integers and how many they would like to evaluate.
5
+ However, users can input any two numbers the wish.
6
6
 
7
7
  ## Installation
8
8
 
@@ -40,34 +40,33 @@ module AddingMultiples
40
40
  # ask user for another integer
41
41
  def get_another_integer
42
42
  input = ""
43
- puts "\nWould you like to enter another number?"
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 input == "y"
51
- get_positive_integer
46
+ if @integer[@i].match(/\d+/)
47
+ sum_integer_multiples
52
48
  else
53
- check_multiples
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 check_multiples
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
@@ -1,3 +1,3 @@
1
1
  module AddingMultiples
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  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.1.3
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-04 00:00:00.000000000 Z
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