~
{2`
$`
T01`p`_p
The leading linefeed is significant.
Try it online!
Explanation
Stage 1: Substitution
~
We start by replacing the empty (non-existent) input with a single ~
.
Stage 2: Substitution
{2`
$`
The regex of this substitution is still empty, since the `
separates configuration from regex and {2
is therefore just the configuration. The {
indicates that the remaining two stages should be run in a loop until they stop changing the output. The 2
indicates that this specific stage has a limit of 2
, meaning that only the first two matches of the regex will be replaced. Since the regex is empty, that means we get an empty match in front of the string and an empty match after the first character.
This match is replaced with the prefix $`
which refers to everything in front of the match. For the first match, there is nothing in front of it, so this doesn't insert anything, but for the second match, there is the leading character in front of it, which therefore gets duplicated.
Stage 3: Transliteration
T01`p`_p
Here, T
activates transliteration mode, and 0
and 1
are limits (where 0
just means "don't set this limit"). Together, they mean "transliterate only the first character in the string". The actual transliteration maps from p
to _p
. Here, p
expands to the printable ASCII characters and _
means "remove" this character, so the expanded lists look like this:
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
_ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
That means spaces get removed and all other characters get decremented by one.
To see how the last two stages act together here is the string after each of the first few and last stages:
~
~~
}~
}}~
|}~
||}~
{|}~
...
"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
""#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
!!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
Since the state of the string is only checked after every other stage to determine whether to end the loop, and the two stages cancel each other once we reach the leading space (since Stage 2 adds a space and Stage 3 removes it), this terminates the loop and therefore the program.
5
Well they are a couple main things about this challenge that are why it's getting downvoted. A) the community really doesn't like it when you ban golfing language (whether or not I agree with this is a different matter) B) it's rather simple but I wouldn't say it's exactly trivial (kinda on the edge). Also saying "Try not to ..." usually isn't a good sign because it's not actually enforcing it (because it's hard to enforce this objectively), and it might mean your challenge may not be found that interesting (therefore getting downvotes).
– Downgoat – 2016-07-11T00:38:51.9808I'm not sure how to interpret try not to hardcode the output here. For a constant output challenge, that's the only way... – Dennis – 2016-07-11T00:50:47.407
@Dennis I meant something like:
echo " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
– dkudriavtsev – 2016-07-11T01:19:32.6771Do we have to print the output from a function or is returning a string acceptable? – Dennis – 2016-07-11T05:53:55.043
1Are built-ins accepted or not? The rule about hardcoding is not clear on that. The MATL answer form @Suever seems to use built-in that contains the printable ASCII. – Fatalize – 2016-07-11T06:37:12.917
2Does "no other characters" include embedded newlines? – Neil – 2016-07-11T07:48:14.683
:( unfortunately the Brainfuck code
+[+.]
(5 bytes) doesn't count as it fails the first rule... – grooveplex – 2016-07-11T11:42:32.8632This is NOT a duplicate of that challenge! Programs there had to accept input and print only part of the table. This challenge is easier and different. – dkudriavtsev – 2016-07-11T23:23:29.510