Your task is to create a polish notation calculator.

For those who don't know what is polish notation, it's a mathematical notation where operators are before the operands.

Eg: + 1 2 = 1 + 2

Your calculator should implement integer addition, substraction multiplication and division.

Standard loopholes are forbidden but you are allowed to use a language even if it's newer than the challenge. Using eval is also forbidden.

Test cases:

Input: + 1 2
Output: 3

Input: * + 3 4 2
Output: 14

Input: / * + - 3 2 9 3 2
Output: 15

Since this is code-golf, the answer with the less bytes win !

  • \$\begingroup\$ @Maltysen No, i add a clarification \$\endgroup\$ – TuxCrafting Jun 18 '16 at 20:05
  • 6
    \$\begingroup\$ Is / integer division, rational division or floating-point division? This is also pretty much a duplicate of codegolf.stackexchange.com/q/221/8478, because any of those solutions can be used here by reversing the tokens first (and since neither challenge allows eval neither order gives a particular advantage to any approach). \$\endgroup\$ – Martin Ender Jun 18 '16 at 20:10
  • \$\begingroup\$ @MartinEnder <s>It's not a duplicate, since this question ask for a polish notation calculator, not a reverse polish notation one</s> Haven't seen the reversing token part. Reversing the tokens would be probably longer than implementing directly a polish notation calculator. Oh and all operations are integer \$\endgroup\$ – TuxCrafting Jun 18 '16 at 20:11
  • \$\begingroup\$ Related: codegolf.stackexchange.com/q/11561/42855 \$\endgroup\$ – Blue Jun 18 '16 at 20:14

Browse other questions tagged or ask your own question.