17
Evaluate a given omnifix expression.
Omnifix is like normal mathematics' infix notation, but with additional copies of each symbol surrounding the arguments. The outer symbols take the place of parentheses, and there is therefore no need for additional parentheses.
You must support addition, subtraction, multiplication, division, and positive real numbers (negative ones can be written -0-n-
) within a reasonable range for your language.
Plus and minus must be +
and -
, but you may use *
or ×
for times and /
or ÷
for divide. Other reasonable symbols will be allowed upon request.
Brownie points for explanation and additional features (like additional operations, negative numbers, strings, etc.) Even if your answer does not have these features, feel free to show how it could.
Please provide a link to test your solution if at all possible.
Examples
For clarity, the explanations below use high minus (¯
) to indicate negative numbers. You may return negative numbers using any reasonable format.
-5-2-
→ 3
+2+×3×2×+
→ 8
(+2+×3×2×+
→ +2+6+
→ 8
)
-14--3-1--
→ 12
(-4--3-1--
→ -14-2-
→ 12
)
+2.1+×3.5×2.2×+
→ 9.8
(+2.1+×3.5×2.2×+
→ +2.1+7.7+
→ 9.8
)
×3×÷-0-6-÷2÷×
→ -9
(×3×÷-0-6-÷2÷×
→ ×3×÷¯6÷2÷×
→ ×3ׯ3×
→ ¯9
)
÷4÷-3-÷1÷2÷-÷
→ 1.6
(÷4÷-3-÷1÷2÷-÷
→ ÷4÷-3-0.5-÷
→ ÷4÷2.5÷
→ 1.6
)
1
The explanations below use high minus (\
¯`) to indicate negative numbers.` You definitely love APL. – Erik the Outgolfer – 2017-07-27T13:16:41.047@EriktheOutgolfer You have a better suggestion? Also, TI-BASIC uses high minus. – Adám – 2017-07-27T13:36:19.190
Actually not since
-
s can be confused with-
s while¯
s can't be confused with-
s. – Erik the Outgolfer – 2017-07-27T13:37:57.530Bah, I just noticed the real number requirement. So much for my 290-byte integer arithmetic Retina solution... – Neil – 2017-07-27T13:43:36.877
@Neil Why don't you post it as an answer? – Adám – 2017-07-31T09:15:46.027
@Adám Your wish is my command! – Neil – 2017-07-31T10:07:12.443