Class: AdditionOperationDifficultyCalculator
Constant Summary
collapse
- DIFFICULTIES =
{
digit_zero: 0, under_ten: 3, ten: 2, above_ten: 4 }
Instance Attribute Summary
#difficulty
Instance Method Summary
collapse
#initialize
Instance Method Details
#compare(numbersa, numbersb) ⇒ Object
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
# File 'lib/hypatia/difficulty-calculator.rb', line 179
def compare(numbersa, numbersb)
numbersa.reverse.each_with_index do |a , index|
b = numbersb.reverse[index]
case
when a == nil || b == nil
@difficulty += DIFFICULTIES[:digit_zero]
when a == 0 || b == 0
@difficulty += DIFFICULTIES[:digit_zero]
when (a + b) == 10
@difficulty += DIFFICULTIES[:ten]
when (a + b) > 10
@difficulty += DIFFICULTIES[:above_ten]
else
@difficulty += DIFFICULTIES[:under_ten]
end
end
end
|
#compute_difficulty ⇒ Object
170
171
172
173
174
175
176
177
|
# File 'lib/hypatia/difficulty-calculator.rb', line 170
def compute_difficulty
if @numbers1.length >= @numbers2.length
compare(@numbers1, @numbers2)
else
compare(@numbers2, @numbers1)
end
@difficulty
end
|