48
\$\begingroup\$

(based on this post and the ensuing discussion on chat -- also, much thanks to Dennis for TIO!)

The Challenge

Choose a language that's currently available on the TryItOnline site, for example PowerShell. Write code in that language on that page, that doesn't take any input, such that when the Run button is clicked, the output on that page is the exact same as what is in the "Plain URL" field when the Save/Store button is clicked instead.

For a fictitious example, suppose that aaa was the code for a solution to this in PowerShell. Then, the result of clicking Run with aaa as the code on https://tio.run/#powershell should output https://tio.run/##K8gvTy0qzkjNyfn/PzEx8f9/AA, which is also the "Plain URL" field when the Save/Store button is clicked.

Scoring

The resulting URL is your submission to this challenge. The winner is the shortest URL measured in bytes. For the example above, the URL https://tio.run/##K8gvTy0qzkjNyfn/PzEx8f9/AA is the submission to the challenge, at 44 bytes. The shortest URL that fulfills the rest of this challenge wins the challenge and earns brownie points (points not redeemable). Given that there is a distinct minimum possible length, if two submissions tie in length, the earlier submission wins.

URL Generation

This is the start of the URL generation algorithm in the repository. You can see how the main code area is taken, any extra elements are appended, the string is deflated and Base64 converted, and then ## prepended, etc. I won't go into full detail here; part of the challenge is to parse and understand how the URLs are generated in order to exploit any potential quirks in said algorithm.

Rules / Clarifications

  • The actual code should take no input and produce only the quine-URL as output.
    -- This means the only text fields that should be populated when clicking into the URL are the Code, Header, Footer or corresponding "Compiler Flag" fields; the Input and Arguments fields are forbidden and must remain empty/unused. Clicking the Run button should only change the Output field. For this challenge, the Debug field is ignored in all situations.
  • Usual quine rules apply to the code to the extent possible (for example, the code cannot read its own source code via .code.tio).
  • Please include a description of how the code works in your submission.
  • Submitting a "cheaty" quine by submitting a Git pull request to the TIO repository to create a "trick" URL or shortcut or the like is not allowed.
  • Similarly, submitting a pull request to update a particular language to produce a "trick" URL is not allowed.
  • Please be nice to Dennis' servers and don't abuse them or attempt exploits for the sake of this challenge.
\$\endgroup\$
13
  • 17
    \$\begingroup\$ Remember, last rule is important! There's already a bunch of DDoS attacks going on. \$\endgroup\$ Jul 19, 2017 at 16:59
  • \$\begingroup\$ What is a "PR"? \$\endgroup\$
    – Adám
    Jul 19, 2017 at 17:09
  • 1
    \$\begingroup\$ Fictitious example: if my submission is https://tio.run/##a+a which links to a program that outputs https://tio.run/##a+a, is it valid even tough the link generated by saveState would have been https://tio.run/##a@a \$\endgroup\$
    – TwiNight
    Jul 20, 2017 at 1:04
  • 1
    \$\begingroup\$ @TwiNight Good question. That would be an interesting situation, but would not fit into the rules here and so would not be a valid submission. \$\endgroup\$ Jul 20, 2017 at 12:29
  • 1
    \$\begingroup\$ Were you waiting until TIOv2 to post this? \$\endgroup\$
    – mbomb007
    Jul 27, 2017 at 21:52

5 Answers 5

16
\$\begingroup\$

Python 2, URL length = 170 bytes

https://tio.run/##K6gsycjPM/r/v9hWqQDCjqlISwPhYlvVIuvM3IL8ohKFpMTiVDMT64KizLwS9YySkoJiK339ksx8vaLSPH1lZXVtiAK9JDOT1Lzk/JRUDY1iVdViTT0YT70qJzNJXVMz2shK1yRWE2aHEkUW4Db//38A
s="python2\xff\xffs=%r;import base64;print'https://tio.run/##'+base64.b64encode((s%%s).encode(('zlib'))[2:-4])\xff\xff";import base64;print'https://tio.run/##'+base64.b64encode((s%s).encode(('zlib'))[2:-4])

Try it online!

This relies on three coincidences:

  1. The default zlib level 6 happens to give the same results as zlib level 9 for this string, modulo the header that I strip.
  2. The compressed length is divisible by 3, so base64 does not generate any = padding characters.
  3. The base64 output does not contain any + characters.
\$\endgroup\$
0
15
\$\begingroup\$

Bash, 174 166 165 157 bytes

https://tio.run/##S0oszvj/v6QosUBBV1dBvaAoM68kTSGjpKSg2EpfvyQzP0avqDRPX1lZRQMqp6RaHFORlgbCSgpJQO0KSgkg/QlKNelVmQU1JYmZOQq6ydqGhjVA2VQzEwXdckNjS011BdcIz5D//wE

This encodes the following Bash program.

trap -- 'printf https://tio\.run/##$(printf "%s\xff\xff" bash "`trap`"|gzip|tail -c+11|base64 -w139)' EXIT

Try it online!

Thanks to @jimmy23013 for golfing 8 bytes off my original approach, for an approach that saved another byte, and for golfing another 8 bytes off that approach!

\$\endgroup\$
11
  • \$\begingroup\$ tio.run/##S0oszvj/… \$\endgroup\$
    – jimmy23013
    Jul 23, 2017 at 11:26
  • 2
    \$\begingroup\$ @jimmy23013 I can't count the number of times I've typed base64 | tr -d \\n into my terminal... Thanks! \$\endgroup\$
    – Dennis
    Jul 23, 2017 at 17:12
  • \$\begingroup\$ tio.run/##S0oszvj/… Unfortunately it has a + that I don't know how to remove. \$\endgroup\$
    – jimmy23013
    Jul 23, 2017 at 17:35
  • \$\begingroup\$ @jimmy23013 Managed to get rid of it, but it cost three bytes. Annoyingly, tio.run/##S0oszvj/… gets rid of that + but introduces another one elsewhere. \$\endgroup\$
    – Dennis
    Jul 23, 2017 at 18:59
  • 3
    \$\begingroup\$ @SteveBennett I think I had a good reason. I don't quite remember it though. \$\endgroup\$
    – Dennis
    Jul 25, 2017 at 2:55
15
+500
\$\begingroup\$

Pyth, URL length = 134 bytes

https://tio.run/##K6gsyfj/X68syy/ZS6lYmyujpKSg2EpfvyQzX6@oNE9fWZnLwae4OLrI3dA9NITLQZ9LM8vZxqSkRC@qOJqrAKiby9vZyNTUmwtiBpefl7e3ppnJ//8A

Code:

.vjNcJ"s+
https://tio.run/##
@Lss[rG1GUT
@/
)jC<4tt.Zs[
pyth
KC255K
.vjNcJ
NJKK)64

Try it online!

Uses Pyth’s zlib builtin (.Z), and an inline implementation of base64.

How it works

The outer stage:

.vjNcJ"…
      "…    take this 75-byte string
     J      assign it to J
    c       split on whitespace
  jN        join on N = '"'
.v          evaluate as Pyth code

The inner stage, obtained by replacing whitespace in the string J with double quotes:

s+"https://tio.run/##"@Lss[rG1GUT"@/")jC<4tt.Zs["pyth"KC255K".vjNcJ"NJKK)64
                                               [                             begin a list:
                                                "pyth"                         string,
                                                       C255                    character 255
                                                      K                        assign that to K,
                                                           K                   K again,
                                                            ".vjNcJ"           string,
                                                                    N          '"',
                                                                     J         J (the 75-byte string),
                                                                      K        K again,
                                                                       K       K again
                                                                        )    end list
                                              s  concatenate
                                            .Z   compress with zlib
                                           t     remove first character
                                          t      remove first character
                                        <4       remove last 4 characters
                                       C         convert from base 256
                                      j                                  64
                                                 convert to base 64 digits
                      @L                         map d ↦ the following indexed at d:
                          [                        begin a list:
                            G                        alphabet ("abcdefghijklmnopqrstuvwxyz")
                           r 1                       uppercase,
                              G                      alphabet again,
                               UT                    unary range of length T = 10: [0, …, 9],
                                 "@/"                string,
                                     )             end list
                         s                         concatenate
                        s                          concatenate (we now have the base64 alphabet)
 +"https://tio.run/##"                           prepend string
s                                                concatenate

(It’s too bad the “Input” field is disallowed, or I’d have a 118 byte solution.)

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Did... Did you just outgolf Dennis on a challenge built around TIO‽ \$\endgroup\$ Aug 14, 2017 at 13:02
5
\$\begingroup\$

PowerShell, 274 bytes

https://tio.run/##TY/rCsIwDIVfZaiYFV2HooIbgu8xBrYzboXSljYq3p59VkHZjxAOJydf4uwVfehQ676fphO5e1TK8pPSWBfF1StCobW8EYYUJMyrphO@qmtw/xzMluv1t37maJoePpsm8sVGP5eV7V25JDslsozmgOJRHAcQ3t6BldARuVDkOcVBfzb5eAwRYM0FPcUQWSkCblaBvDJtPLxaLDmPnTf2bCjbsppxj06LBlPYwRxgoGdR74E9vw9mnQ2UZObF@v4N

It's all thanks to the following snippet:

&($b={[io.file]::writeallbytes('b',[char[]]'powershell'+255+255+[char[]]"&(`$b={$b})"+255+255);gzip -f b;$b=[io.file]::readallbytes('b.gz');'https://tio.run/##'+[convert]::tobase64string($b[12..($b.count-9)]).replace('=','').replace('+','@')|write-host -n})

Try it online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Holy christ, can you explain how you got to this answer? If I even tried in Java or something it'd be pure trial and error. \$\endgroup\$ Aug 1, 2017 at 21:17
4
\$\begingroup\$

JavaScript (Node.js), 214 bytes

v=()=>console.log('https://tio.run/##'+require(`zlib`).deflateRawSync(Buffer.from(`javascript-node\xff\xffv=`+v+`;v()\xff\xff`,`ascii`)).toString("base64"));v()

Try it online!

\$\endgroup\$

Your Answer

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

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