Thursday, July 5, 2012

Reverse Polish Notation

I came up with an algorithm to convert infix expressions to rpn at work the other day while trying to think about how to create and store logical expressions and upon not immediately finding any Ruby gems that do rpn conversions I decided to make it my FIRST EVER GEM omgroflbbq.

Anyway, it turned out my original idea of storing an insert point doesn't work when you have things like operator precedence, so I punted to wikipedia and found this:

http://en.wikipedia.org/wiki/Shunting-yard_algorithm

One hour later I had a fully speced gem covering converting simple algebra.

https://rubygems.org/gems/rpn-converter
https://github.com/kwstannard/rpn-converter