[Daily Coding Problem 371] Solve Arithmetic Equations

You are given a series of arithmetic equations as a string, such as:

 

y = x + 1
5 = x + 3
10 = z + y + 2

The equations use addition only and are separated by newlines. Return a mapping of all variables to their values. If it's not possible, then return null. In this example, you should return:

{
  x: 2,
  y: 3,
  z: 5
}

The solution offered by Daily Coding Problem is a simpified version, and incorrect when there is no single-variable equation or there are conflicting single-variable equations.Solving a system of linear equations is a lot more involved than that. 

Refer to the following for more information.
https://en.wikipedia.org/wiki/Gaussian_elimination
https://www.geeksforgeeks.org/gaussian-elimination/

 
posted @ 2019-12-04 12:19  Review->Improve  阅读(310)  评论(0编辑  收藏  举报