laurpaik-zz / ruby-rpn-calculator-challenge

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

General Assembly Logo

RPN (Reverse Polish Notation) Calculator Challenge

Adapted from this CodeWars exercise, created by user vgrichina.

RPN, or Reverse Polish Notation, is a convention for writing arithemetic expressions. Ordinarily, most arithemetic expressions are written as 1 + 2: the operation is in the middle, with arguments (in this case, 1 and 2) on either side. In Polish Notation, this order is changed so that the operation comes before all of the arguments, i.e. + 1 2.

Reverse Polish Notation is almost the same, as Polish Notation, except that the operation comes after all of the arguments, i.e. 1 2 +

Your challenge will be to create a simplified calculator for evaluating expressions written in RPN.

Please note your calculator should be able to handle expressions with more than one operation.

Prerequisites

  • None

Instructions

  1. Fork and clone this repository.
  2. Change into the new directory.
  3. Install dependencies.
  4. Create and checkout a new branch to work on.
  5. Fulfill the listed requirements.

Starter code is available in lib/challenge.rb. A pull request is not required, but it is necessary if you want a code review.

You may wish to refer to FAQs related to forking, cloning.

Requirements

Implement a method calc which, given a string of characters written in RPN, returns the result of the operations. For now, the calculator should only implement four operations: +, -, *, or /.

Additionally, note that:

  • If the expression is empty, it should evaluate to zero.
  • The calculator must also work with floating point numbers (i.e. decimals).

For simplicity's sake, assume that all strings are properly formatted, with a single space between every character, and that your calculator will not be given any unusual operations (such as dividing by zero).

You should be running rubocop before diagnosing any bugs, since it finds some of the most common sources of errors. After rubocop passes your code (ignore any warnings about spec_helper), you should run rake test to run the included tests, which will tell you whether or not you've met requirements.

  1. All content is licensed under a CC­BY­NC­SA 4.0 license.
  2. All software code is licensed under GNU GPLv3. For commercial use or alternative licensing, please contact legal@ga.co.

About

License:Other


Languages

Language:Ruby 100.0%