Skip to content

Commit

Permalink
📝 hierarchical-parentheses description
Browse files Browse the repository at this point in the history
  • Loading branch information
razorcd authored Jun 4, 2018
1 parent dc084ab commit 3918742
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions hierarchical-parentheses/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## Describing the logic

To write mathematical equations we used 3 types of parenthesis: `(), [], {}` and these were always hierarchical like this: `{[()]}`, always in this order. And to go even further we would reuse the curly braces like this `{ { { [ ( ) ] } } }`. It's like [Matryoshka doll](https://en.wikipedia.org/wiki/Matryoshka_doll) from Russia. :)

An example would be: `{(4 + 1) * { 5 * [( 5 ^ 2 - 4 ^ 2 ) * 2 ]}} / 2`. (where `5^2` means 5 to the power of 2).

## Describing the challenge

We need an application that would take a mathematical equation as string for input and return a boolean response representing the validity of the parenthesis ordering.

Some valid equations for which the application would return `true`:
- `5 * 5`
- `(4 + 1) * 2`
- `(4 + 1) * [(2 - 4) / (2 + 2)]`
- `{(4 + 1) * { 5 * [( 5 ^ 2 - 4 ^ 2 ) * 2 ]}} / 2`

Some invalid equations for which the application would return `false`:
- `(4 + 1) * 2)`
- `[4 + 1] * 2`
- `4 * ([2 - 4] / [2 + 2])`
- `4 * {(2 - 4) / (2 + 2)}`
- `([4 * [1 + 2] - 1])`

0 comments on commit 3918742

Please sign in to comment.