For the expression:
res = ((v + 10) * (i - 2)) / 3
My program builds the following binary tree:
(=)
├─ (res)
└─ (/)
├─ (3)
└─ (*)
├─ (+)
│ ├─ (v)
│ └─ (10)
└─ (-)
├─ (i)
└─ (2)
To obtain a solution for variable v, I manually solve it like this:
((v + 10) * (i - 2)) / 3 = res
(v + 10) * (i - 2) = res * 3
v + 10 = (res * 3) / (i - 2)
v = ((res * 3) / (i - 2)) - 10
How can I programmatically do the same operation?
For example, given the binary tree and its specific node (in this case v), rebuild this tree so that it evaluates to that node:
(=)
├─ (v) <-- my node
└─ (-)
├─ (10)
└─ (/)
├─ ...
└─ ...