chain is a sum and difference of fractions written as numerator/denominator, for example "1/3-1/2+5/6". The first fraction may be preceded by a minus sign; a plus sign is never written in front of it.
Evaluate it and return the result as a string holding a fully reduced fraction p/q with a positive denominator. A negative result starts with a minus sign, a positive one has no sign. A whole number is written with denominator 1, such as "2/1", and zero is "0/1".chain="3/4-1/6" → '7/12'
3/4 − 1/6 = 9/12 − 2/12 = 7/12.
chain="-2/3+1/6+1/2" → '0/1'
−4/6 + 1/6 + 3/6 = 0, and zero is written as 0/1.
chain="5/2+3/2" → '4/1'
The sum is 4, a whole number, so the answer is 4/1.
/, +, -chain="3/4-1/6"
'7/12'
Run checks the first 3 tests in your browser. Submit checks all 96 tests on the server, hidden ones included.