Reverse Polish Notation with power

3.5k Views Asked by At

Perhaps I'm just not understanding RPN correctly, but whenever I translate something like

2^2^3 then I get 22^3^

But if I try to execute that it's wrong! Because that will result in 64 (4^3), but what I need it to do is result in 256 (2^8)

How do I fix this?

1

There are 1 best solutions below

1
On BEST ANSWER

You need 2 2 3 ^ ^, because exponentiation is normally understood from right to left. That is, something like 2^2^3 means 2^(2^3), not (2^2)^3. So when you convert to RPN that's how you have to convert it.