4
\$\begingroup\$

What tips do you have for golfing in (,)? I've found that there are so many ways to make code shorter, and I want more ways. I doubt there even are any tips for (,) that are applicable in the majority of programming languages, but if there are, feel free to include them.

Please, one tip per answer.

\$\endgroup\$

4 Answers 4

4
\$\begingroup\$

Nest Variables

When you have a variable (lets say A) with a index at least two more than a constant, fairly large variable B (or at least constant while you use A), you can usually instead have A be var[B]. Or, you can nest it more deeply.

For an example of how this can help, first assume all variables are constant, sufficiantly large, and sufficiantly distinct. Then, with only one set of parentheses characters you can only make one variable: (). With 2, ()() and (()). With 3, ()()(), (())(), (()()), ((())). With 4, ()()()(), (())()(), (()())(), ((()))(), (()()()), ((())()), ((()())), (((()))), (())(()).

As you can see, it more than doubles for each new set of parentheses. However, since you usually don't have all constant variables, you should try out each reasonable combination of variable orderings to see which is smallest, and also keep in mind that constant variables greatly increase total accessable variables.

\$\endgroup\$
2
\$\begingroup\$

Take advantage of flags

There are a ton of flags currently existing. 'D' is only useful for debugging, but all others can be useful. The 's'/'S' flags are only useful for golfing, and can help cut down on commas used. 'i' is useful when input is an integer, 'm' is useful for multiplication of negative numbers, 'n' and 'N' are useful for different output formats, and 'd' is useful only rarely.

\$\endgroup\$
2
\$\begingroup\$

Nest print statements

When you are printing values of variables you could have a situation like this:

(,,(()))(,,(()()))

Where we are printing var1 followed by var2. Thanks to the fact that referring to a variable in the first argument does not require surrounding the variable address in parentheses, we could do this instead:

(,,(()(),,(())))

Where the inner statement prints var1 and returns the value of var2, to be printed by the outer statement for two less bytes.

With this approach it is still possible to do sums before printing, and this saved me lots of bytes in my (,) quine.

\$\endgroup\$
1
\$\begingroup\$

Edit variables when you use them

Title is fairly self-explanatory. Instead of going [something](var)[something](var,[something]), you can usually shorten it to [something](var,[something])[something], because var access happens before var setting (aka return value += vars[var_to_access] happens before vars[var_to_access] = value_to_set_var_to).

An example

To output then increment variable one, instead of writing (,,(()))((),(())()) write (,,((),(()))).

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.