Problem 1307. RPN Calculator for simple arithmetic expressions
Reverse-Polish-Notation (RPN) is a machine friendly form of calculating expressions. Example, to evaluate, (1+2)*4 + 5 - 3 you enter the sequence into the calculator as, '5 1 2 + 4 * + 3 -' and obtain the result.
For this challenge write a RPN calculator for simple arithmetic expressions, '+','-','*','%','/'
Note: Chosen interpretations of operators, illustrated from first few test cases, are as follows: rpn('a','b','-') is interpreted as 'a-b', while rpn('a','b','/') is interpreted as 'b/a'. and rpz('a','b','%') which is interpreted as 'b%a'.
with operator '%' 'b % a' being mod(b,a) operator.
Following your 'stack' solution to http://www.mathworks.com/matlabcentral/cody/problems/1303-is-the-paranthesis-sequence-balanced try using a expression, and a value stack to work this problem.
Solution Stats
Problem Comments
-
6 Comments
Show
3 older comments
Baki
on 6 Nov 2016
I have an rpn solver but it only accepts strings
ChrisR
on 21 Aug 2022
Would someone please check the first test? The variable z is commented out.
Dyuman Joshi
on 21 Aug 2022
Chris, the format of the test cases has been corrected, you can attempt the question now.
Solution Comments
Show commentsProblem Recent Solvers12
Suggested Problems
-
Extract leading non-zero digit
2189 Solvers
-
233 Solvers
-
617 Solvers
-
120 Solvers
-
Given a matrix, return the last eigen value
225 Solvers
More from this Author10
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!