Giter Club home page Giter Club logo

ruby-rpn-calculator-challenge's Introduction

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 [email protected].

ruby-rpn-calculator-challenge's People

Contributors

ga-meb avatar realweeks avatar bengitscode avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.