We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
1) A somewhat simple and algorithmical way to consider every parenthesis grouping is generating and evaluating every valid Postfix Expression.
2) If you use floating point numbers, limited precission gives wrong answers for some tests. An alternative to using more precission, maybe a little more messy, is solving it using only integer numbers. That can be achieved if you use (integer) numerators and denominators in the operations (for example, you can implement a rational number class with two integer fields and all four operations)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #93: Arithmetic expressions
You are viewing a single comment's thread. Return to all comments →
Two observations that may help:
1) A somewhat simple and algorithmical way to consider every parenthesis grouping is generating and evaluating every valid Postfix Expression.
2) If you use floating point numbers, limited precission gives wrong answers for some tests. An alternative to using more precission, maybe a little more messy, is solving it using only integer numbers. That can be achieved if you use (integer) numerators and denominators in the operations (for example, you can implement a rational number class with two integer fields and all four operations)