I see your BIDMAS and raise you a BADMIS
Challenge
Given a set of numbers with operators between them: "5 + 4 * 9 / 3 - 8", return all the possible results of the expression for every permutation of the order of basic operations: [/, *, +, -].
Rules
- Standard loopholes forbidden
- I/O
- Input must be ordered with infix operations, but however that is easiest (string or array)
- You are not required to support unary operators (e.g. "-3 * 8 / +2")
- Integers can be replaced by floats for languages that implicitly parse type (e.g. 45 ⟶ 45.0)
- Output must be all of the possible results of the expression, no specified format or order
- All of the inputs are valid (e.g. do not need to deal with "7 / 3 + *"). This also means that you will never need to divide by zero.
- Operators are all left-associative so "20 / 4 / 2" = "(20 / 4) / 2"
- This is Code Golf so fewest number of bytes wins
Test Cases (With explanation)
- "2 + 3 * 4" = [14, 20]
- 2 + (3 * 4) ⟶ 2 + (12) ⟶ 14
- (2 + 3) * 4 ⟶ (5) * 4 ⟶ 20
- "18 / 3 * 2 - 1" = [11, 2, 6]
- ((18 / 3) * 2) - 1 ⟶ ((6) * 2) - 1 ⟶ (12) - 1 ⟶ 11
- (18 / 3) * (2 - 1) ⟶ (6) * (1) ⟶ 6
- (18 / (3 * 2)) - 1 ⟶ (18 / (6)) - 1 ⟶ (3) - 1 ⟶ 2
- 18 / (3 * (2 - 1)) ⟶ 18 / (3 * (1)) ⟶ 6
- 18 / ((3 * 2) - 1) ⟶ 18 / 5 ⟶ 3.6
Test Cases (Without explanation)
- "45 / 8 + 19 / 45 * 3" = [6.891666666666667, 18.141666666666666, 0.11111111111111113, 0.01234567901234568, 0.01234567901234568, 5.765740740740741]
- "2 + 6 * 7 * 2 + 6 / 4" = [112 196 23 87.5]
2 - 3 + 4
=>[-5, 3]
\$\endgroup\$2*3-6+2-9/6*8+5/2-9
, giving 24 distinct results. \$\endgroup\$