Evaluating Simple Algebra
Challenge Difficulty: Medium | Estimated completion time: ~20 minutes
Given a string containing an algebraic equation, calculate and return the value of x.
You’ll only be given equations for simple addition and subtraction.
Examples
evalAlgebra("2 + x = 19")
output = 17
evalAlgebra("4 - x = 1")
output = 3
evalAlgebra("x + 10 = 53")
output = 43
evalAlgebra("-23 + x = -20")
output = 3
evalAlgebra("10 + x = 5")
output = -5
evalAlgebra("-49 - x = -180")
output = 131
evalAlgebra("x - 22 = -56")
output = -34Solution
Python
Output