Skip to content

Instantly share code, notes, and snippets.

# Put your answers here!
Michael-Riess-Computer:~ michaelriess$ rvm list
rvm rubies
ruby-1.8.7-p302 [ i686 ]
ruby-1.9.2-p290 [ x86_64 ]
=* ruby-1.9.2-p318 [ x86_64 ]
ruby-1.9.2-p320 [ x86_64 ]
@mhriess
mhriess / gist:3452431
Created August 24, 2012 16:15
Reverse Polish Notation Calculator
Create an RPNCalculator class which can evaluate expressions
written in Reverse Polish notation.
It should have an evaluate instance method which takes as its
input a valid RPN expression and returns its evaluation. Your
calculator only needs to handle addition, multiplication, and
subtraction (not division).
Operators and numbers should be separated by a single space.
Write a method mode which takes an Array of numbers
as its input and returns an Array of the most frequent values.
If there's only one most-frequent value, it returns a
single-element Array.
For example,
mode([1,2,3,3]) # => [3]
mode([4.5, 0, 0]) # => [0]