I was browsing esolangs, and chanced upon this language: https://github.com/catseye/Quylthulg.
One interesting thing about this language, is that it doesn't use prefix, postfix, or infix, it uses all three of them, calling it "panfix" notation.
Here is an example. To represent normal infix
1+2 in panfix, it becomes:
+1+2+. Notice how the operator is both before, in between, and after the operands. Another example is
(1+2)*3. This becomes
*+1+2+*3*. Notice again how
* is in all three places with respect to the operands
As you may have guessed, your task in this challenge is to convert an expression from infix to panfix.
A few clarifications:
- You only have to deal with the four basic operations:
- You won't have to deal with the unary versions of those, only binary
- You have to deal with parenthesis
- Assume the normal precedence rules of
+-and left associativity for all of them.
- The numbers will be nonnegative integers
- You can optionally have a spaces in both the input and output
1+2 -> +1+2+ 1+2+3 -> ++1+2++3+ (1+2)*3 -> *+1+2+*3* 10/2*5 -> */10/2/*5* (5+3)*((9+18)/4-1) -> *+5+3+*-/+9+18+/4/-1-*
This is code-golf, so shortest code in bytes wins!