Ad
  • Default User Avatar

    Thanks for looking at my solution and giving some feedback!

    I agree that it might be overkill for the problem as stated. But when time permits, I always try to go for the solution that is easiest to maintain/update over time (e.g. low code churn, only having to make changes in one spot).

    The lambda isn't really required for my solution. I could just hard code it to 2 and then update it if new operators are ever added. But then again, that violates my goal of only having to make a change in one spot.

    The stringstream I thought was the fastest way of doing string concatenation, but Google searching shows that I'm probably wrong. So I could easily have just used a string instead.

    The precedence offset was simply my way of handling parentheses (especially nested parentheses). Too bad it looked like a jigsaw puzzle. I strive for readability as well.

  • Default User Avatar

    However your solution might be more universal if there would be a need to expand for more operators, in my opinion using structs + map + lambda + stringstream + some jigsaw-puzzle with offsets is a little bit overshoot to the current problem's size.

    Although my appreciation for the not copy-paste-from-somewhere solution.