7
1
The worst part about long lines or code or math equations are the parentheses. Nobody wants to read through 2x(3y+4*abs(x^[2*e^x])-5{3(x+y)-5})!
So, the goal of this challenge is to make it at least slightly easier to read these parentheses-filled beasts! For the above math equation, the output should be:
2x (
3y+4*abs (
x^ [
2*e^x
]
)
-5 {
3 (
x+y
)
-5
}
)
A parenthesis is defined as either of these characters: ()[]{}
. Indents should each be two spaces, and there should be one space of seperation between the expression and the parenthesis: 2x (
, x^ [
as some examples.
I would like to debut the Atomic Code Golf metric in this question. Take out all separators in your code (()[]{}. ;
to name some common ones), and then take the length of your program if every reserved word and operator were 1 character long. That is your program's score. if x**(3.2)==b[3]:print x
is 11 points: if|x|**|3|.|2|==|b|3|print|x
, or ix*3.2=b3px
. Any quick questions about the metric can be posted here; larger questions should be discussed in meta using the link above.
Lowest score wins. Good luck, have fun!
Related. (The differences being that the other question asks for K&R style bracket placement and that it's plain code golf.) – Martin Ender – 2015-09-21T10:22:31.517
The unary answer will win. – coredump – 2015-10-05T07:58:46.720
Are names from standard libraries considered "reserved words"? – Ben – 2015-10-05T19:49:15.183
Is
$x
one token or two? – mob – 2013-02-21T03:59:25.410@mob: Depends on what
$x
is: if it's a variable, 1 token. If it's a math operator, then 2. – beary605 – 2013-02-21T04:14:17.573Love the scoring system, I think it will make Common Lisp much more viable. – Strigoides – 2013-02-27T20:14:04.207
Re. the task itself: do we have to check for matching brackets, or is it okay to assume that they are all correctly matched up? Furthermore, is the input expression guaranteed to contain no whitespace already? (In particular, in the vicinity of the parens..) – FireFly – 2013-03-06T16:16:00.187
@FireFly: They're all correctly matched (there will be as many open brackets as there are closed brackets). Yes, there will be no whitespace. – beary605 – 2013-03-07T00:57:56.067