Big Numbers

The maximum integer Ruby stores is either 2^30 -1 or 2^62 -1, depending on your system.

2^30 - 1 = 1,073,741,823

2^62 - 1 = 4,611,686,018,427,387,903

For a computer system, adding two really big numbers is impossible because it will exceed the maximum integer value. But, we can use strings and write a program to manually do it for us, just like adding two numbers on paper with a pen. For example:

a = "25256262652562"

b = "8790087923478963673763168867989797"

a + b = "8790087923478963673788425130642359"

Write a function that takes two strings representing numbers, and returns a string that is equivalent to the sum of the two numbers. (Numbers have no decimal part)

def addBig(num1, num2)
  # your magic here
end

results matching ""

    No results matching ""