Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. def string_evaluation(string)
  2. values_mult = string.scan(/\d+[*]\d+/)
  3.  
  4. values_mult.each do |math|
  5. i, j = math.scan(/\d+/)
  6. string = string.gsub! math, (i.to_i*j.to_i).to_s
  7. end
  8.  
  9. if !string.scan(/\d+[*]\d+/).empty?
  10. string_evaluation(string)
  11. else
  12. values_sum = string.scan(/\d+/)
  13. sum = values_sum.map(&:to_i).reduce(:+)
  14. puts sum
  15. end
  16. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement