Skip to content

Commit 361879a

Browse files
committed
feat(codewars): add 2kyu problem
1 parent 7b2306d commit 361879a

File tree

5 files changed

+668
-1
lines changed

5 files changed

+668
-1
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
"book",
1010
"codewars",
1111
"exercism"
12-
]
12+
],
13+
"git.branchProtectionPrompt": "alwaysCommit"
1314
}

Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "eval_math_expression"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Evaluate mathematical expression
2+
3+
[codewars](https://www.codewars.com/kata/52a78825cdfc2cfc87000005/train/rust)
4+
5+
Instructions
6+
Given a mathematical expression as a string you must return the result as a number.
7+
8+
Numbers
9+
Number may be both whole numbers and/or decimal numbers. The same goes for the returned result.
10+
11+
Operators
12+
You need to support the following mathematical operators:
13+
14+
Multiplication *
15+
Division / (as floating point division)
16+
Addition +
17+
Subtraction -
18+
Operators are always evaluated from left-to-right, and * and / must be evaluated before + and -.
19+
20+
Parentheses
21+
You need to support multiple levels of nested parentheses, ex. (2 / (2 + 3.33) * 4) - -6
22+
23+
Whitespace
24+
There may or may not be whitespace between numbers and operators.
25+
26+
An addition to this rule is that the minus sign (-) used for negating numbers and parentheses will never be separated by whitespace. I.e all of the following are valid expressions.
27+
28+
1-1 // 0
29+
1 -1 // 0
30+
1- 1 // 0
31+
1 - 1 // 0
32+
1- -1 // 2
33+
1 - -1 // 2
34+
1--1 // 2
35+
36+
6 + -(4) // 2
37+
6 + -( -4) // 10
38+
And the following are invalid expressions
39+
40+
1 - - 1 // Invalid
41+
1- - 1 // Invalid
42+
6 + - (4) // Invalid
43+
6 + -(- 4) // Invalid
44+
Validation
45+
You do not need to worry about validation - you will only receive valid mathematical expressions following the above rules.
46+
47+
Restricted APIs
48+
NOTE: std::process::Command is disallowed in your solution.

0 commit comments

Comments
 (0)