0

Say I'm given an expression like

(1/2) + (3/4) + (5/8) + (2/10) + (3/2) + (10/1)

How might I go about computing this expression as a float value in such a way that if the expression where to change I could still compute it?

I initially thought I could parse it from a string but ran into big problems. I then shifted to manually cutting the values into two arrays - Denominators and numerators but I felt that that was cheating the spirit of the exercise a bit. It also wouldn't allow flexibility in terms of the values presented.

Can this be done without 3rd party libraries and the like?

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • 1
    "that if the expression where to change I could still compute it?"... can you please explain this more clearly – stinepike Jun 26 '13 at 03:51
  • I mean to say: If I where handed a similar expression to compute, would I be able to use the same method or class to compute it. – user2522420 Jun 26 '13 at 03:58
  • "Can this be done without 3rd party libraries and the like?" - Simple answer. Yes. Read the linked questions. (Evaluating the parsed expression tree is easy ...) – Stephen C Jun 26 '13 at 04:05
  • Re: "I initially thought I could parse it from a string but ran into big problems": You should delete this question, and instead, ask questions about those problems. Because yes, you should be able to parse it from a string. – ruakh Jun 26 '13 at 04:38

0 Answers0