-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
📝 hierarchical-parentheses description
- Loading branch information
Showing
1 changed file
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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])` |