Guest User

Untitled

a guest
Oct 20th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.26 KB | None | 0 0
  1. a = "1234345"
  2. b = "1239"
  3. c = 0
  4. r = []
  5. max = a.length > b.length ? a.length : b.length
  6.  
  7. (1..max).each{ |i|
  8. n = a[-i].to_i + b[-i].to_i + c
  9. p n
  10. if n < 10 then
  11. c = 0
  12. r.unshift n
  13. else
  14. r.unshift n % 10
  15. c = n / 10
  16. end
  17.  
  18. }
  19.  
  20. p r.join
Add Comment
Please, Sign In to add comment