From 9999d34d9a2145563fd9b30fec0f8d61a42c91ee Mon Sep 17 00:00:00 2001 From: Divlo Date: Tue, 29 Sep 2020 08:22:14 +0000 Subject: [PATCH] feat: add reverse-polish-notation challenge --- challenges/reverse-polish-notation/README.md | 25 ++++++++++++++ .../reverse-polish-notation/input-output.json | 34 +++++++++++++++++++ .../solutions/.gitkeep | 0 3 files changed, 59 insertions(+) create mode 100644 challenges/reverse-polish-notation/README.md create mode 100644 challenges/reverse-polish-notation/input-output.json create mode 100644 challenges/reverse-polish-notation/solutions/.gitkeep diff --git a/challenges/reverse-polish-notation/README.md b/challenges/reverse-polish-notation/README.md new file mode 100644 index 0000000..50a8a6f --- /dev/null +++ b/challenges/reverse-polish-notation/README.md @@ -0,0 +1,25 @@ +# reverse-polish-notation + +Created by [@Divlo](https://github.com/Divlo) on 29 September 2020. + +## Instructions : + +Your job is to create a calculator which evaluates expressions in Reverse Polish notation (a mathematical notation in which operators follow their operands. It does not need any parentheses as long as each operator has a fixed number of operands). + +For example expression 5 1 2 + 4 * + 3 - (which is equivalent to 5 + ((1 + 2) * 4) - 3 in normal notation) should evaluate to 14. + +For your convenience, the input is formatted such that a space is provided between every token. + +Empty expression should evaluate to 0. + +Valid operations are +, -, *, /. + +You may assume that there won't be exceptional situations (like stack underflow or division by zero). + +## Source : + +- [Reverse polish notation - Codewars](https://www.codewars.com/kata/52f78966747862fc9a0009ae) + +## Examples : + +See the `input-output.json` file for examples of input/output. diff --git a/challenges/reverse-polish-notation/input-output.json b/challenges/reverse-polish-notation/input-output.json new file mode 100644 index 0000000..f75c3ce --- /dev/null +++ b/challenges/reverse-polish-notation/input-output.json @@ -0,0 +1,34 @@ +[ + { + "input": [""], + "output": 0 + }, + { + "input": ["3"], + "output": 3 + }, + { + "input": ["3.5"], + "output": 3.5 + }, + { + "input": ["1 3 +"], + "output": 4 + }, + { + "input": ["1 3 *"], + "output": 3 + }, + { + "input": ["1 3 -"], + "output": -2 + }, + { + "input": ["4 2 /"], + "output": 2 + }, + { + "input": ["5 3 + 12 8 + * 10 /"], + "output": 16 + } +] diff --git a/challenges/reverse-polish-notation/solutions/.gitkeep b/challenges/reverse-polish-notation/solutions/.gitkeep new file mode 100644 index 0000000..e69de29