Jun 1, 2020 7:12 AM
| Last Modified: Jun 1, 2020 7:18 AM
In last month’s challenge, I had to avoid creating a situation where overflow error might cause additional complications. In fact, the algorithm for modular exponentiation in the Miller-Rabin based isPrime routine is written to avoid this problem. Inevitably, you will run across this issue regardless of the programming language.
An overflow error occurs when you try to perform an operation requiring more bits than are available to represent the results. This often, but not exclusively, occurs when working with large integers. For example, try the following examples:
x = 9007199254740992;
x = 9007199254740992;
n1 = 9007199254740999;
n2 = 1;
253 is the largest integer that JMP can represent before overflow happens. Here’s a nice explanation of floating-point representation (all numbers in JMP are floating point). For this month’s challenge, I would like to see you come up with methods for adding and subtracting numbers that would overflow JMP’s representation of integers. Create two functions
subtractBig(n1,n2) where n1 and n2 are both integers (positive, negative, or 0) in text form. Returns a value in text form.
n1 – integer in text form or, if n2 is empty, a list of integers (positive, negative, or 0) in text form.
5 points for a version of addBig that can 1) add two numbers of at most 1000 digits in under 30 seconds, and 2) find the sum of a list containing at most 100, 100-digit numbers in under 30 seconds. Part 1) will be tested with 10 different sets of numbers. The number of digits in each number will not necessarily be the same. The same set of 10 will be used for all submissions.
3 additional points for subtractBig, which must compute (x – y), where x and y are numbers of at most 1000 digits, in under 30 seconds. Ten different sets of numbers will be used. The number of digits for each number will not necessarily be the same. The same set of 10 will be used for all submissions.
3 bonus points for the addBig submission that can correctly add the largest (number of digit) n1 and n2 of equal lengths, in under 5 seconds. (2 points for 2nd, 1 for the 3rd)
3 bonus points for the addBig submission that can correctly add the most 1000-digit numbers in under 5 seconds (2 points for 2nd, 1 point for 3rd).
3 extra points each if any submission is as fast or faster than any submission by a JMP staff member.
Submission deadline is 11:59 PM Eastern (US) time Monday, June 15. Good luck!