Skip to content

Latest commit

 

History

History
 
 

10_BONUS_rpn

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Week 5 Home

U2.W5: Implement a Reverse Polish Notation calculator

Learning Objectives

  • Decompose a problem into smaller, easier to solve components
  • Manipulate and access data within data structures
  • Find and use built-in Ruby methods to solve challenges

Background

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.

For example,

calc = RPNCalculator.new

calc.evaluate('1 2 +')   # => 3
calc.evaluate('2 5 *')   # => 10
calc.evaluate('50 20 -') # => 30

# The general rule is that 'A B op' is the same as 'A op B'
# i.e., 5 4 - is 5 - 4.
calc.evaluate('70 10 4 + 5 * -') # => 0

Directions

  1. Run the Rspec tests, and then translate at least 3 of the tests into Driver Test Code and include it in the driver code section. If the tests are failing to catch a problem, try writing your own driver test code for it.
  2. Pseudocode
  3. Initial Solution
  4. Refactored Solution
  5. Reflect
  6. Sync your changes (push your solution) to Github
  7. Review