Too lazy to figure out how to deal with the remainder in division, but here is a cut at a calculator in Ruby that doesn't use math operators.
def add(num_1, num_2) [num_1, num_2].sum end def multiply(num_1, num_2) arr = [] num_1.times do |n| arr << num_2 end arr.sum end def subtract(num_1, num_2) subtractable = num_2.positive? ? "-#{num_2}".to_i : num_2.to_s.gsub("-", "").to_i [num_1, subtractable].sum end def divide(num_1, num_2) arr = [] while num_1 >= num_2 arr << "whatever" num_1 = subtract(num_1, num_2) end arr.size end
Wow .sum is a function in Ruby? That made it so easy.
Yeah, that's sort of a cheat — but Ruby's like that 🤣
eval("10 + 10") also would have been a quick answer here, but that seemed just a bit too easy.
eval("10 + 10")
Oh- wow
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Too lazy to figure out how to deal with the remainder in division, but here is a cut at a calculator in Ruby that doesn't use math operators.
Wow .sum is a function in Ruby? That made it so easy.
Yeah, that's sort of a cheat — but Ruby's like that 🤣
eval("10 + 10")also would have been a quick answer here, but that seemed just a bit too easy.Oh- wow