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 try using a expression, and a value stack to work this problem.


Solution Stats

25.64% Correct | 74.36% Incorrect
Last solution submitted on Feb 08, 2017

Problem Comments

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!