Recently I've been writing a new language, to avoid needing to handle order of operations, I simply parenthesize each expression properly to avoid this entirely.
Because parenthesis are at char-codes 40-41, your code will need to be as short as possible.
Examples
1+2*3
(1+(2*3))
2*(3+4)
(2*(3+4))
2*3/4+3
(((2*3)/4)+3)
342*32/8
((342*32)/8)
Rules
The only operations you'll need to handle are: *
(multiplication), /
(division), +
(addition), and -
(subtraction).
- The order of operations is:
- Parenthesis
- Multiplication, Division
- Adition, Subtraction
- You should prefer to go left-right
- The input numbers will always be positive integers (see bonuses)
Bonuses
-20% if you handle negation:
3+-5
(3+(-5))
-5% if you allow spaces to be placed inside the input:
3 + 4
(3+4)
-10% if you can handle decimals in the input:
1+.12
(1+.12)
1+0.21/3
(1+(0.21/3))
500 bounty: if you manage to write an answer in Unnamed/Blocks
1+2+3+4
(which certain solutions might parenthesise as((1+2)+(3+4))
) \$\endgroup\$