Tips for golfing in ///

12

1

What general tips do you have for golfing in ///? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to /// (e.g. "remove unnecessary whitespace" is not an answer). Tips for itflabtijtslwi and Lines are on-topic and valid here as well.

Please post one tip per answer.

Comrade SparklePony

Posted 2017-05-12T22:45:36.527

Reputation: 5 784

Answers

5

Use // as a replacement

When you define a bunch of replacements, e.g.:

/a/b//c/d//e/f//g/h//i/j//k/l//m/n//o/p//q/r//s/t//u/v//w/x//y/z/

(65 bytes). You can use // as a replacement:

/~/\/\///a/b~c/d~e/f~g/h~i/j~k/l~m/n~o/p~q/r~s/t~u/v~w/x~y/z/

(61 bytes).

Comrade SparklePony

Posted 2017-05-12T22:45:36.527

Reputation: 5 784

4

Incomplete /// blocks are not printed

Note that this line of code

/Stack/Overflow//x/\//Stack/ignore/DoItyignore

prints only Overflow - the part from /ignore onwards is not included in the output, because /// only prints things in its third slash-part.

Try the incomplete block online!

It is however still considered by the replacer: if we were to inject a slash in there, things change:

/Stack/Overflow//x/\//Stack/ignore/doitxignore

Try that online!

Output here is Overflowdoit, because replacing x with / made it valid syntax.

steenbergh

Posted 2017-05-12T22:45:36.527

Reputation: 7 772

4

When expanding on a basis and printing intermediate results, incorporate previous iterations in future ones

That sounded a bit convoluted. What I mean might better be described using an actual answer. This challenge requires this specific output:

Steve Ballmer still does not know.
Steve Ballmer still does not know what he did.
Steve Ballmer still does not know what he did wrong.
Steve Ballmer still does not know what he did wrong with mobile.

One naive solution might be:

/1/Steve Ballmer still does not know//2/ what he did//3/ wrong//4/ with mobile./1.
12.
123.
1234

Notice how the pattern 1, 12,123 ... is repeated? Well, not when you do this:

/1/Steve Ballmer still does not know//2/1 what he did//3/2 wrong//4/3 with mobile/1.
2.
3.
4.

Once again, thanks go to Martin Ender for pointing this out!

steenbergh

Posted 2017-05-12T22:45:36.527

Reputation: 7 772

2

Use a character at the end of code to handle edge cases

When you have a piece of /// code that handles all but one case, then you can use a character at the edge of the code to handle the edge case.

Example: Unary add two numbers together unless the second number is 7, in which case just output the first number.

Code that handles all but the "second number is 7" case:

/+//<INPUT 1>+<INPUT 2>

By adding a * to the end of the code, we can handle the edge case by replacing +0000000* with nothing (it is necessary to include the + to makes sure the number is not greater than 7). Make sure to include code at the end before the input to clean it up.

/+0000000*///+///*//<INPUT 1>+<INPUT 2>*

Try it online!

For a "real-world" example, I used this trick on some of the "Jimmy" problems:

Comrade SparklePony

Posted 2017-05-12T22:45:36.527

Reputation: 5 784