Skip to main content
4 of 5
This remark is irrelevant thanks to recent rule changes.
Nissa
  • 3.6k
  • 1
  • 18
  • 45

7, 2 (or 1⅞ or 1⅝, depending on how you count) bytes

7 is an Underload derivative that I've been working on over the past few days. Being an Underload derivative, it's particularly good at quines, so I thought I'd come to this challenge first. (Unlike Underload, though, it has support for input. Like Underload, it's Turing-complete, thus meaning it can handle all the tasks required to be an actual programming language.)

The program itself can be expressed either in octal encoding (there are only 8 commands, named 0, 1, 2, 3, 4, 5, 6, and 7, that can appear in a 7 source file):

23723

or packed into bytes (the language sees them as raw octets; I've expressed them as codepage 437 here):

(The interpreter ignores trailing 1 bits, so arguably this program can be golfed down to only 13 bits = 1⅝ bytes long via removing the language's equivalent of "trailing whitespace". Languages like this are a little hard to count.)

Here's how the program works. 2 encodes "duplicate", 3 encodes "output and pop twice", thus the combination 23 means "output and pop". The program will thus start by pushing two 23 units on the stack (these are initially inert, but become active as they're pushed). Because the end of the program was reached, it's replaced by the top stack element, without disturbing the stack; thus the text of the second 23 gets output and popped. (As it's active rather than inert, what actually gets output is a string representation, 723, but the first 7 is interpreted as a formatting code that specifies "the output should be in the same encoding as the program itself", meaning that the quine works in both encodings.) Then the same thing happens for the first 23; this time, the whole 723 gets output, leading to an output of 23723 (or ).

This is a true quine via all the definitions we commonly use on SE. For example, the first 23 encodes the second 23 and vice versa, meaning that part of the program encodes a different part of the output. Likewise, this quine could handle a payload just fine. If you didn't require a true quine, you could use the following ⅜-byte program:

3

which is a proper quine by some definitions, but not others. (The stack starts with two bars on it, meaning that the extra pop that occurs after the output is printed is harmless.)

user62131