Fractions Addition and Subtraction

Published by Evgeny SH in

The function is given a string representing an expression of many fractions addition and subtraction. Compute the arithmetic result and return the string in the form of an irreducible fraction. Even if the result is an integer, e.g. 3, return it as 3/1.

Examples

fractions_addition("-1/2+1/2") ➞ "0/1"

fractions_addition("-1/2+1/2+1/3") ➞ "1/3"

fractions_addition("1/3-1/2") ➞ "-1/6"

fractions_addition("5/3+1/3") ➞ "2/1"

Notes

N/A

Watch a quick demo on how Edabit works.