Class: SubtractionOperationDifficultyCalculator
- Inherits:
-
OperationDifficultyCalculator
- Object
- OperationDifficultyCalculator
- SubtractionOperationDifficultyCalculator
- Defined in:
- lib/hypatia/difficulty-calculator.rb
Constant Summary collapse
- DIFFICULTIES =
{ digit_zero: 1, # difference of zero and any digit same_digits: 1, # difference of same values digits even_even: 2, # difference of even digits odd_odd: 2, # difference of odd digits even_odd: 3, # difference of even and odd digits borrow: 2, # doing a borrow twodigit_digit: 4 # difference of two-digit number and digit }
Instance Attribute Summary
Attributes inherited from OperationDifficultyCalculator
Instance Method Summary collapse
Methods inherited from OperationDifficultyCalculator
Constructor Details
This class inherits a constructor from OperationDifficultyCalculator
Instance Method Details
#compute_difficulty ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/hypatia/difficulty-calculator.rb', line 67 def compute_difficulty if @numbers1.length < @numbers2.length @difficulty += DIFFICULTIES[:borrow] end @numbers1.reverse.each_with_index do | a , index | b = @numbers2.reverse[index] case when a == nil || b == nil @difficulty += DIFFICULTIES[:digit_zero] when a == 0 || b == 0 if a == 0 @difficulty += DIFFICULTIES[:borrow] end @difficulty += DIFFICULTIES[:digit_zero] when a == b @difficulty += DIFFICULTIES[:same_digits] when a < b @difficulty += DIFFICULTIES[:borrow] else @difficulty += DIFFICULTIES[:even_odd] end end @difficulty end |