https://github.com/hauntedhost/rpn-calculator
"Reverse Polish Notation" calculator
https://github.com/hauntedhost/rpn-calculator
Last synced: 8 months ago
JSON representation
"Reverse Polish Notation" calculator
- Host: GitHub
- URL: https://github.com/hauntedhost/rpn-calculator
- Owner: hauntedhost
- Created: 2013-08-05T08:26:54.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2015-10-21T16:39:39.000Z (over 10 years ago)
- Last Synced: 2025-07-29T11:59:24.704Z (11 months ago)
- Language: Ruby
- Homepage:
- Size: 117 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
RPN Calculator
==============
"RPN" stands for "Reverse Polish Notation". (See the wikipedia entry for more information on this colorful term.) Briefly, in an RPN world, instead of using normal "infix" notation, e.g.
```
2 + 2
```
you use "postfix" notation, e.g.
```
2 2 +
```
While this may seem bizarre, there are some advantages to doing things this way. For one, you never need to use parentheses, since there is never any ambiguity as to what order to perform operations in. The rule is, you always go from the back, or the left side.
```
1 + 2 * 3 =>
(1 + 2) * 3 or
1 + (2 * 3)
1 2 + 3 * => (1 + 2) * 3
1 2 3 * + => 1 + (2 * 3)
```
Another advantage is that you can represent any mathematical formula using a simple and elegant data structure, called a stack).
Hints
-----
Ruby doesn't have a built-in stack, but the standard Array has all the methods you need to emulate one (namely, push and pop, and optionally size).