(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.


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.
  • 16
    \$\begingroup\$ Remember, last rule is important! There's already a bunch of DDoS attacks going on. \$\endgroup\$ – Erik the Outgolfer Jul 19 '17 at 16:59
  • \$\begingroup\$ What is a "PR"? \$\endgroup\$ – Adám Jul 19 '17 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 '17 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\$ – AdmBorkBork Jul 20 '17 at 12:29
  • 1
    \$\begingroup\$ Were you waiting until TIOv2 to post this? \$\endgroup\$ – mbomb007 Jul 27 '17 at 21:52

Python 2, URL length = 170 bytes

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.

Bash, 174 166 165 157 bytes


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!

  • \$\begingroup\$ tio.run/##S0oszvj/… \$\endgroup\$ – jimmy23013 Jul 23 '17 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 '17 at 17:12
  • \$\begingroup\$ tio.run/##S0oszvj/… Unfortunately it has a + that I don't know how to remove. \$\endgroup\$ – jimmy23013 Jul 23 '17 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 '17 at 18:59
  • 3
    \$\begingroup\$ @SteveBennett I think I had a good reason. I don't quite remember it though. \$\endgroup\$ – Dennis Jul 25 '17 at 2:55

Pyth, URL length = 134 bytes




Try it online!

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

How it works

The outer stage:

      "…    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:

                                               [                             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.)

  • 2
    \$\begingroup\$ Did... Did you just outgolf Dennis on a challenge built around TIO‽ \$\endgroup\$ – Engineer Toast Aug 14 '17 at 13:02

PowerShell, 274 bytes


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!

  • 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\$ – Magic Octopus Urn Aug 1 '17 at 21:17

JavaScript (Node.js), 214 bytes


Try it online!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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