Golf you a quine for great good!

166

41

Using your language of choice, golf a quine.

A quine is a non-empty computer program which takes no input and produces a copy of its own source code as its only output.

No cheating -- that means that you can't just read the source file and print it. Also, in many languages, an empty file is also a quine: that isn't considered a legit quine either.

No error quines -- there is already a separate challenge for error quines.

Points for:

  • Smallest code (in characters)
  • Most obfuscated/obscure solution
  • Using esoteric/obscure languages
  • Successfully using languages that are difficult to golf in

The following Stack Snippet (adapted from this question) can be used to get a quick view of the current score in each language, and thus to know which languages have existing answers and what sort of target you have to beat:

var QUESTION_ID = 69;
var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe"; var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk";
var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page;
function answersUrl(index) { return "https://api.stackexchange.com/2.2/questions/" + QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER; }
function commentUrl(index, answers) { return "https://api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER; }
function getAnswers() { jQuery.ajax({ url: answersUrl(answer_page++), method: "get", dataType: "jsonp", crossDomain: true, success: function (data) { answers.push.apply(answers, data.items); answers_hash = []; answer_ids = []; data.items.forEach(function(a) { a.comments = []; var id = +a.share_link.match(/\d+/); answer_ids.push(id); answers_hash[id] = a; }); if (!data.has_more) more_answers = false; comment_page = 1; getComments(); } }); } function getComments() { jQuery.ajax({ url: commentUrl(comment_page++, answer_ids), method: "get", dataType: "jsonp", crossDomain: true, success: function (data) { if (data.has_more) getComments(); else if (more_answers) getAnswers(); else process(); } }); }
getAnswers();
var SCORE_REG = /<h\d>\s*([^\n,<]*(?:<(?:[^\n>]*>[^\n<]*<\/[^\n>]*>)[^\n,<]*)*),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;
var OVERRIDE_REG = /^Override\s*header:\s*/i;
function getAuthorName(a) { return a.owner.display_name; }
function process() { var valid = []; answers.forEach(function(a) { var body = a.body; a.comments.forEach(function(c) { if(OVERRIDE_REG.test(c.body)) body = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>'; }); var match = body.match(SCORE_REG); if (match) valid.push({ user: getAuthorName(a), size: +match[2], language: match[1], link: a.share_link, }); else console.log(body); }); valid.sort(function (a, b) { var aB = a.size, bB = b.size; return aB - bB }); var languages = {}; var place = 1; var lastSize = null; var lastPlace = 1; valid.forEach(function (a) { if (a.size != lastSize) lastPlace = place; lastSize = a.size; ++place; var answer = jQuery("#answer-template").html(); answer = answer.replace("{{PLACE}}", lastPlace + ".") .replace("{{NAME}}", a.user) .replace("{{LANGUAGE}}", a.language) .replace("{{SIZE}}", a.size) .replace("{{LINK}}", a.link); answer = jQuery(answer); jQuery("#answers").append(answer); var lang = a.language; lang = jQuery('<a>'+lang+'</a>').text(); languages[lang] = languages[lang] || {lang: a.language, lang_raw: lang.toLowerCase(), user: a.user, size: a.size, link: a.link}; }); var langs = []; for (var lang in languages) if (languages.hasOwnProperty(lang)) langs.push(languages[lang]); langs.sort(function (a, b) { if (a.lang_raw > b.lang_raw) return 1; if (a.lang_raw < b.lang_raw) return -1; return 0; }); for (var i = 0; i < langs.length; ++i) { var language = jQuery("#language-template").html(); var lang = langs[i]; language = language.replace("{{LANGUAGE}}", lang.lang) .replace("{{NAME}}", lang.user) .replace("{{SIZE}}", lang.size) .replace("{{LINK}}", lang.link); language = jQuery(language); jQuery("#languages").append(language); } }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<style>body { text-align: left !important} #answer-list { padding: 10px; width: 290px; float: left; } #language-list { padding: 10px; width: 290px; float: left; } table thead { font-weight: bold; } table td { padding: 5px; }</style>
<link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> 
<div id="language-list"> <h2>Shortest Solution by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr> </thead> <tbody id="languages"> </tbody> </table> </div> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr> </thead> <tbody id="answers"> </tbody> </table> </div> <table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr> </tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr> </tbody> </table>

Rafe Kettler

Posted 2011-01-28T00:34:05.293

Reputation: 1 034

1I'm disappointed nobody's found one for Malbolge yet. – JDL – 2016-10-21T09:09:11.900

2@JDL the malbolge quine has actually existed for years – Pavel – 2017-01-13T07:21:10.643

I offer 100 rep for a Reflections quine.

– wastl – 2018-03-08T07:57:49.320

4Do you not mean, "Golf you a quine for greater good!"? – Mateen Ulhaq – 2011-05-03T02:49:07.960

40@muntoo it's a play on "Learn you a Haskell for Great Good". – Rafe Kettler – 2011-05-03T02:52:14.103

10what about random text generator quines (a probability that the program will print itself) – Ming-Tang – 2011-05-14T00:01:42.043

Answers

77

Hexagony, side-length 17 16, 816 705 bytes

180963109168843880558244491673953327577233938129339173058720504081484022549811402058271303887670710274969455065557883702369807148960608553223879503892017157337685576056512546932243594316638247597075423507937943819812664454190530214807032600083287129465751195839469777849740055584043374711363571711078781297231590606019313065042667406784753422844".".>.@.#.#.#.#.#.#.#.>.(...........................<.".......".".>./.4.Q.;.+.<.#.>...........................<.".....".".>.#.#.>.N.2.'.\.>.............=.=......._.<.".....".".>.>.;.'.=.:.\.>.......................<."...".".>.\.'.%.'.<.#.>..............._.....<."...".".>.#.#.>.<.#.>...............=.=.<.".".".>.#.\.'.R./.>.................<.".!.........../.>.

Try it online!

This is what it looks like unfolded:

                1 8 0 9 6 3 1 0 9 1 6 8 8 4 3 8
               8 0 5 5 8 2 4 4 4 9 1 6 7 3 9 5 3
              3 2 7 5 7 7 2 3 3 9 3 8 1 2 9 3 3 9
             1 7 3 0 5 8 7 2 0 5 0 4 0 8 1 4 8 4 0
            2 2 5 4 9 8 1 1 4 0 2 0 5 8 2 7 1 3 0 3
           8 8 7 6 7 0 7 1 0 2 7 4 9 6 9 4 5 5 0 6 5
          5 5 7 8 8 3 7 0 2 3 6 9 8 0 7 1 4 8 9 6 0 6
         0 8 5 5 3 2 2 3 8 7 9 5 0 3 8 9 2 0 1 7 1 5 7
        3 3 7 6 8 5 5 7 6 0 5 6 5 1 2 5 4 6 9 3 2 2 4 3
       5 9 4 3 1 6 6 3 8 2 4 7 5 9 7 0 7 5 4 2 3 5 0 7 9
      3 7 9 4 3 8 1 9 8 1 2 6 6 4 4 5 4 1 9 0 5 3 0 2 1 4
     8 0 7 0 3 2 6 0 0 0 8 3 2 8 7 1 2 9 4 6 5 7 5 1 1 9 5
    8 3 9 4 6 9 7 7 7 8 4 9 7 4 0 0 5 5 5 8 4 0 4 3 3 7 4 7
   1 1 3 6 3 5 7 1 7 1 1 0 7 8 7 8 1 2 9 7 2 3 1 5 9 0 6 0 6
  0 1 9 3 1 3 0 6 5 0 4 2 6 6 7 4 0 6 7 8 4 7 5 3 4 2 2 8 4 4
 " . " . > . @ . # . # . # . # . # . # . # . > . ( . . . . . .
  . . . . . . . . . . . . . . . . . . . . . < . " . . . . . .
   . " . " . > . / . 4 . Q . ; . + . < . # . > . . . . . . .
    . . . . . . . . . . . . . . . . . . . . < . " . . . . .
     " . " . > . # . # . > . N . 2 . ' . \ . > . . . . . .
      . . . . . . . = . = . . . . . . . _ . < . " . . . .
       . " . " . > . > . ; . ' . = . : . \ . > . . . . .
        . . . . . . . . . . . . . . . . . . < . " . . .
         " . " . > . \ . ' . % . ' . < . # . > . . . .
          . . . . . . . . . . . _ . . . . . < . " . .
           . " . " . > . # . # . > . < . # . > . . .
            . . . . . . . . . . . . = . = . < . " .
             " . " . > . # . \ . ' . R . / . > . .
              . . . . . . . . . . . . . . . < . "
               . ! . . . . . . . . . . . / . > .
                . . . . . . . . . . . . . . . .

Ah well, this was quite the emotional rollercoaster... I stopped counting the number of times I switched between "haha, this is madness" and "wait, if I do this it should actually be fairly doable". The constraints imposed on the code by Hexagony's layout rules were... severe.

It might be possible to reduce the side-length by 1 or 2 without changing the general approach, but it's going to be tough (only the cells with # are currently unused and available for the decoder). At the moment I also have absolutely no ideas left for how a more efficient approach, but I'm sure one exists. I'll give this some thought over the next few days and maybe try to golf off one side-length, before I add an explanation and everything.

Well at least, I've proven it's possible...

Some CJam scripts for my own future reference:

Martin Ender

Posted 2011-01-28T00:34:05.293

Reputation: 162 549

29Dear pete what is this. – Conor O'Brien – 2016-02-26T23:05:21.527

2How long did it take to make this? – Adnan – 2016-02-26T23:13:38.617

2@AandN I've been playing around with concepts for a general "template" since yesterday now and then (that didn't involve any actual testing... just typing up some stuff on a 7x7 grid and seeing if it might work... I discarded probably half a dozen approaches already there). The actual coding then took this evening... maybe 3 hours, I'd say. – Martin Ender – 2016-02-26T23:15:59.713

Well, my guess of 23 was a bit off... :P – Riker – 2016-02-26T23:23:22.757

@RikerW Hey, I'm not done yet! (That said, yes it was.) – Martin Ender – 2016-02-26T23:23:50.667

Are you done yet? – Riker – 2016-04-03T20:43:51.603

@EasterlyIrk Ummm, not quite... I've got a couple of ideas, but I haven't found the motivation yet to sit down for another 3-hour Hexagony session to try them out. :P – Martin Ender – 2016-04-03T20:46:05.010

2Words can't explain how astonished I am when seeing this in action with Esoteric IDE step by step...

To whom may want to understand this, this Hexagon encodes the "decoder" part into an integer which is printed with ! and then with a mirror / on the 2nd last line it enters the decoder to print the decoder code to complete the quine.

This has a miraculous use of &lt; and &gt; which reads the multiline very big integer and built the area for storing the decoder.

I'd really love to know what "dozens of approaches" are being considered? – Sunny Pun – 2016-10-24T05:48:59.640

1Explanation? --- – MD XF – 2017-06-16T04:21:06.203

66

MySQL, 167 characters

SELECT REPLACE(@v:='SELECT REPLACE(@v:=\'2\',1+1,REPLACE(REPLACE(@v,\'\\\\\',\'\\\\\\\\\'),\'\\\'\',\'\\\\\\\'\'));',1+1,REPLACE(REPLACE(@v,'\\','\\\\'),'\'','\\\''));

That's right. :-)

I really did write this one myself. It was originally posted at my site.

TehShrike

Posted 2011-01-28T00:34:05.293

Reputation: 820

66

GolfScript, 2 bytes

1

(note trailing newline) This pushes the number 1 onto the stack. At the end of the program, GolfScript prints out all items in the stack (with no spaces in between), then prints a newline.

This is a true quine (as listed in the question), because it actually executes the code; it doesn't just "read the source file and print it" (unlike the PHP submission).


For another example, here's a GolfScript program to print 12345678:

9,(;
  1. 9: push 9 to the stack
  2. ,: consume the 9 as an argument, push the array [0 1 2 3 4 5 6 7 8] to the stack
  3. (: consume the array as an argument, push the array [1 2 3 4 5 6 7 8] and the item 0 to the stack
  4. ;: discard the top item of the stack

The stack now contains the array [1 2 3 4 5 6 7 8]. This gets written to standard output with no spaces between the elements, followed by a newline.

Chris Jester-Young

Posted 2011-01-28T00:34:05.293

Reputation: 3 397

71Technically, 1 is not a quine in GolfScript: it outputs 1\n, where \n denotes a newline. However, the two-char program 1\n is a quine. – Ilmari Karonen – 2012-02-03T08:27:39.457

8@Pseudonym a quine is literally a program which prints its own source. I don't think there are any arbitrary restrictions on "structure". – Hugo Zink – 2015-09-24T11:07:23.523

@Rokk When Hofstader coined the term, he was specifically thinking of Quine's paradox. "Self-replicating program" or "self-copying program" is the more general term. – Pseudonym – 2015-09-24T11:11:51.043

@Pseudonym I see, thanks for the explanation. – Hugo Zink – 2015-09-24T11:14:36.993

@Pseudonym This program doesn't just print its own source. I've expanded with an explanation. – Chris Jester-Young – 2015-09-24T11:37:50.193

@ChrisJester-Young I don't dispute that it's a real, non-cheating self-replicating program. I'm just saying it's not a quine, which is a certain kind of self-replicating program. – Pseudonym – 2015-09-24T12:12:25.697

16Or PowerShell, or PHP :-) – Joey – 2011-01-28T09:54:27.763

15The one-char program \n probably also is? – Lynn – 2013-08-23T14:51:02.620

No, Ilmari, even that is not a quine. A quine is not just a program which prints its own source, it has to have a specific structure to be a quine. – Pseudonym – 2014-02-12T05:59:45.270

3You didn't go back in time and give the inventor the idea to invent GolfScript, did you? – Mateen Ulhaq – 2011-05-03T02:38:31.560

60

Prelude, 5157 4514 2348 1761 1537 664 569 535 423 241 214 184 178 175 169 148 142 136 133 bytes

Thanks to Sp3000 for saving 3 bytes.

This is rather long... (okay, it's still long ... at least it's beating the shortest known Brainfuck C# quine on this challenge now) but it's the first quine I discovered myself (my Lua and Julia submissions are really just translations of standard quine techniques into other languages) and as far as I'm aware no one has written a quine in Prelude so far, so I'm actually quite proud of this. :)

7( -^^^2+8+2-!( 6+ !
  ((#^#(1- )#)8(1-)8)#)4337435843475142584337433447514237963742423434123534455634423547524558455296969647344257)

That large number of digits is just an encoding of the core code, which is why the quine is so long.

The digits encoding the quine have been generated with this CJam script.

This requires a standard-compliant interpreter, which prints characters (using the values as character codes). So if you're using the Python interpreter you'll need to set NUMERIC_OUTPUT = False.

Explanation

First, a few words about Prelude: each line in Prelude is a separate "voice" which manipulates its own stack. These stacks are initialised to an infinite number of 0s. The program is executed column by column, where all commands in the column are executed "simultaneously" based on the previous stack states. Digits are pushed onto the stack individually, so 42 will push a 4, then a 2. There's no way to push larger numbers directly, you'll have to add them up. Values can be copied from adjacent stacks with v and ^. Brainfuck-style loops can be introduced with parentheses. See the link in the headline for more information.

Here is the basic idea of the quine: first we push loads of digits onto the stack which encode the core of the quine. Said core then takes those digits,decodes them to print itself and then prints the digits as they appear in the code (and the trailing )).

This is slightly complicated by the fact that I had to split the core over multiple lines. Originally I had the encoding at the start, but then needed to pad the other lines with the same number of spaces. This is why the initial scores were all so large. Now I've put the encoding at the end, but this means that I first need to skip the core, then push the digits, and jump back to the start and do the printing.

The Encoding

Since the code only has two voices, and and adjacency is cyclic, ^ and v are synonymous. That's good because v has by far the largest character code, so avoiding it by always using ^ makes encoding simpler. Now all character codes are in the range 10 to 94, inclusive. This means I can encode each character with exactly two decimal digits. There is one problem though: some characters, notably the linefeed, have a zero in their decimal representation. That's a problem because zeroes aren't easily distinguishable from the bottom of the stack. Luckily there's a simple fix to that: we offset the character codes by 2, so we have a range from 12 to 96, inclusive, that still comfortably fits in two decimal digits. Now of all the characters that can appear in the Prelude program, only 0 has a 0 in its representation (50), but we really don't need 0 at all. So that's the encoding I'm using, pushing each digit individually.

However, since we're working with a stack, the representations are pushed in reverse. So if you look at the end of the encoding:

...9647344257

Split into pairs and reverse, then subtract two, and then look up the character codes:

57 42 34 47 96
55 40 32 45 94
 7  (     -  ^

where 32 is corresponds to spaces. The core does exactly this transformation, and then prints the characters.

The Core

So let's look at how these numbers are actually processed. First, it's important to note that matching parentheses don't have to be on the same line in Prelude. There can only be one parenthesis per column, so there is no ambiguity in which parentheses belong together. In particular, the vertical position of the closing parenthesis is always irrelevant - the stack which is checked to determine whether the loop terminates (or is skipped entirely) will always be the one which has the (.

We want to run the code exactly twice - the first time, we skip the core and push all the numbers at the end, the second time we run the core. In fact, after we've run the core, we'll push all those numbers again, but since the loop terminates afterwards, this is irrelevant. This gives the following skeleton:

7(
  (                   )43... encoding ...57)

First, we push a 7 onto the first voice - if we don't do this, we'd never enter the loop (for the skeleton it's only important that this is non-zero... why it's specifically 7 we'll see later). Then we enter the main loop. Now, the second voice contains another loop. On the first pass, this loop will be skipped because the second stack is empty/contains only 0s. So we jump straight to the encoding and push all those digits onto the stack. The 7 we pushed onto the first stack is still there, so the loop repeats.

This time, there is also a 7 on the second stack, so we do enter loop on the second voice. The loop on the second voice is designed such that the stack is empty again at the end, so it only runs once. It will also deplete the first stack... So when we leave the loop on the second voice, we push all the digits again, but now the 7 on the first stack has been discarded, so the main loop ends and the program terminates.

Next, let's look at the first loop in the actual core. Doing things simultaneously with a ( or ) is quite interesting. I've marked the loop body here with =:

-^^^2+8+2-!
(#^#(1- )#)
 ==========

That means the column containing ( is not considered part of the loop (the characters there are only executed once, and even if the loop is skipped). But the column containing the ) is part of the loop and is ran once on each iteration.

So we start with a single -, which turns the 7 on the first stack into a -7... again, more on that later. As for the actual loop...

The loop continues while the stack of digits hasn't been emptied. It processes two digits at a time,. The purpose of this loop is to decode the encoding, print the character, and at the same time shift the stack of digits to the first voice. So this part first:

^^^
#^#

The first column moves the 1-digit over to the first voice. The second column copies the 10-digit to the first voice while also copying the 1-digit back to the second voice. The third column moves that copy back to the first voice. That means the first voice now has the 1-digit twice and the 10-digit in between. The second voice has only another copy of the 10-digit. That means we can work with the values on the tops of the stacks and be sure there's two copies left on the first stack for later.

Now we recover the character code from the two digits:

2+8+2-!
(1- )#

The bottom is a small loop that just decrements the 10-digit to zero. For each iteration we want to add 10 to the top. Remember that the first 2 is not part of the loop, so the loop body is actually +8+2 which adds 10 (using the 2 pushed previously) and the pushes another 2. So when we're done with the loop, the first stack actually has the base-10 value and another 2. We subtract that 2 with - to account for the offset in the encoding and print the character with !. The # just discards the zero at the end of the bottom loop.

Once this loop completes, the second stack is empty and the first stack holds all the digits in reverse order (and a -7 at the bottom). The rest is fairly simple:

( 6+ !
8(1-)8)#

This is the second loop of the core, which now prints back all the digits. To do so we need to 48 to each digit to get its correct character code. We do this with a simple loop that runs 8 times and adds 6 each time. The result is printed with ! and the 8 at the end is for the next iteration.

So what about the -7? Yeah, 48 - 7 = 41 which is the character code of ). Magic!

Finally, when we're done with that loop we discard the 8 we just pushed with # in order to ensure that we leave the outer loop on the second voice. We push all the digits again and the program terminates.

Martin Ender

Posted 2011-01-28T00:34:05.293

Reputation: 162 549

1Listening to Hello World in Fugue right now... pretty catchy. – Robert Fraser – 2015-04-29T03:29:29.123

17Martin, you gotta stop somewhere. – seequ – 2016-02-25T21:12:09.623

50

Brain-Flak, 9.8e580 1.3e562 9.3e516 12818 11024 4452 4332 4240 4200 4180 3852 3656 3616 3540 2485 + 3 = 2488 bytes

Now fits in the observable universe!

(())(()()())(())(())(()()())(())(())(()()())(())(()()()()())(()())(()()()()())(())(()()())(())(()()()()())(())(())(())(())(()()()()())(())(())(()()())(())(())(()()())(())(()()()()())(()())(()()()()())(())(()()())(())(()()()()())(())(())(())(())(())(())(()())(())(())(())(()())(()()()())(())(()()()()())(()())(()())(()())(()()())(())(()())(())(()()()()())(()())(()()()()())(())(())(())(())(())(()())(())(())(())(()()()()())(())(())(()()()()())(())(())(()()()()())(())(())(()())(())(()())(())(()())(())(()())(())(()())(()())(()())(()())(()())(()())(()())(()())(())(()()()()())(())(())(()()())(())(())(()()())(())(()()()()())(()())(()()()()())(())(()()())(())(())(()()())(()())(())(()()()()())(())(())(()()())(())(())(()()())(())(()()()()())(()())(()()()()())(())(())(())(()()())(())(())(()()())(())(())(()()())(())(()()()()())(()())(()()()()())(()()())(())(()()())(())(())(())(()())(()()())(()())(())(()()()()())(()())(())(()()())(())(()()()()())(())(())(())(()()())(())(())(())(()())(())(()())(()()()())(())(())(()()()()())(()())(()())(())(()()())(())(())(())(())(()()())(()())(())(())(()()()()())(())(())(()()()()())(())(())(()()()()())(())(())(()())(())(()())(())(()())(())(()())(()())(()())(()())(())(()()()()())(()())(())(()()())(())(()()()()())(()()()()())(())(()()())(())(())(()())(())(()()()()())(())(()()()()())(())(())(())(()()()()())(())(())(()())(())(()())(())(()())(())(()())(())(()())(()())(()())(()())(())(()()()()())(()())(())(()()())(())(())(()())(())(()()()()())(()())(()()()()())(())(()()())(())(())(()()()()())(())(()()()()())(())(())(())(()())(())(()()()()())(())(())(()())(())(()())(())(()())(()())(()())(()())(())(()()()()())(()())(())(()()()()())(())(()()())(())(())(()())(())(()()()()())(()())(()()()()())(())(()()())(())(())(())(()())(()()()())(())(())(()())(())(()()()()())(())(())(()()()()())(())(())(()()()()())(())(())(()())(())(()())(())(()())(())(()())(())(()())(()())(()())(()())(()())(()())(())(()()())(())(())(()())(())(()()()()())(()())(()()()()())(()()())(())(())(()())(())(())(()()()()())(()()()())(()())(()())(()()())(())(()())(())(()()()()())(()())(()()()()())(())(())(())(()()()())(()()()())(()())([[]]){({}()<(([{}]())<{({}())<>(((((()()()()()){}){}){}())[()])<>{({}())<>{}({}(((()()()){}())){}{})<>{({}())<>({}(((()()()()()){})){}{}())<>{{}<>({}(((()()()()){}){}){})(<>)}}<>(({})[()()])<>}}{}<>({}(<()>)<><{({}<>)<>}<>>){({}<>)<>}{}(<>)<>{({}<>)<>}{}(((((((()()()()()){}){}){}))()))>){({}()<((({}[()])()))>)}{}<>{({}<>)<>}{}>)}{}<>{({}<>)<>}<>

Try it online!


Explanation

This Quine works like most Quines in esoteric languages; it has two parts an encoder and a decoder. The encoder is all of the parentheses at the beginning and the decoder is the more complex part at the very end.

A naive way of encoding the program would be to put the ASCII value of every character in the decoder to the stack. This is not a very good idea because Brain-Flak only uses 8 characters (()<>[]{}) so you end up paying quite a few bytes to encode very little information. A smarter idea, and the one used up until now is to assign each of the 8 braces to an much smaller number (1-8) and convert these to the ASCII values with our decoder. This is nice because it costs no more than 18 bytes to encode a character as opposed to the prior 252.

However this program does neither. It relies on the fact that Brain-Flak programs are all balanced to encode the 8 braces with the numbers up to 5. It encodes them as follows.

(       -> 2
<       -> 3
[       -> 4
{       -> 5
),>,],} -> 1

All the close braces are assigned 1 because we can use context to determine which of them we need to use in a particular scenario. This may sound like a daunting task for a Brian-Flak program, but it really is not. Take for example the following encodings with the open braces decoded and the close braces replaced with a .:

(.
((..
<([.{...

Hopefully you can see that the algorithm is pretty simple, we read left to right, each time we encounter a open brace we push its close brace to an imaginary stack and when we encounter a . we pop the top value and put it in place of the .. This new encoding saves us an enormous number of bytes in the encoder while only losing us a handful of bytes on the decoder.

Low level explanation

Work in progress

Wheat Wizard

Posted 2011-01-28T00:34:05.293

Reputation: 33 549

14I think you win for longest solution to a code-golf challenge... – Mego – 2016-10-04T10:40:12.720

11Just made the largest single golf in the history of PPCG Nope. 9.8e580 is still impressive though. – Dennis – 2016-10-04T17:15:57.933

2... very big golf ... – Destructible Lemon – 2016-12-09T23:21:55.737

2I think you win for most bytes cut off – Christopher – 2017-02-25T02:18:20.723

39

Brainf*ck (755 characters)

This is based off of a technique developed by Erik Bosman (ejbosman at cs.vu.nl). Note that the "ESultanik's Quine!" text is actually necessary for it to be a quine!

->++>+++>+>+>++>>+>+>+++>>+>+>++>+++>+++>+>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>+>+>++>>>+++>>>>>+++>+>>>>>>>>>>>>>>>>>>>>>>+++>>>>>>>++>+++>+++>+>>+++>>>+++>+>+++>+>++>+++>>>+>+>+>+>++>+++>+>+>>+++>>>>>>>+>+>>>+>+>++>+++>+++>+>>+++>+++>+>+++>+>++>+++>++>>+>+>++>+++>+>+>>+++>>>+++>+>>>++>+++>+++>+>>+++>>>+++>+>+++>+>>+++>>+++>>>+++++++++++++++>+++++++++++++>++++++>+++++++++++++++>++++++++++>+++>+++>++++>++++++++++++++>+++>++++++++++>++++>++++++>++>+++++>+++++++++++++++>++++++++>++++>++++++++++++>+++++++++++++++>>++++>++++++++++++++>+++>+++>++++>++++++>+++>+++++++++>++++>+>++++>++++++++++>++++>++++++++>++>++++++++++>+>+++++++++++++++>+++++++++++++
ESultanik's Quine!
+[[>>+[>]+>+[<]<-]>>[>]<+<+++[<]<<+]>>+[>]+++[++++++++++>++[-<++++++++++++++++>]<.<-<]

ESultanik

Posted 2011-01-28T00:34:05.293

Reputation: 1 048

3@proudhaskeller IIRC, the part before ESultanik's Quine! sets up the memory as a stack encoding ESultanik's Quine! and onward, with two bytes of memory for each character (ASCII value offsets from 0x1F). The final bit of code loops through the memory, first programmatically reproducing the ++&gt;+++… codes for each character, then actually printing the characters. – ESultanik – 2016-02-09T15:48:20.197

Can be golfed by removing unnecessary chars like newlines, 'E"s, and other insignificant characters. – CalculatorFeline – 2016-03-07T05:31:41.537

3@CatsAreFluffy They are required for it to be a quine! While it is true that they could be removed, one would also have to change the preceding code to maintain the quine property. – ESultanik – 2016-03-07T12:05:50.087

1That's true. Also the newlines are necessary. – CalculatorFeline – 2016-03-07T16:39:04.973

12That's a clever way to do it. – Peter Olson – 2011-06-22T16:48:11.263

12How does it work? – proud haskeller – 2014-09-13T16:21:34.933

39

Vim, 11 bytes

q"iq"qP<Esc>hqP
  • iq"qP<Esc>: Manually insert a duplicate of the text that has to be outside the recording.
  • q" and hqP: Record the inside directly into the unnamed "" register, so it can be pasted in the middle. The h is the only repositioning required; if you put it inside the macro, it will be pasted into the result.

Edit

A note about recording with q": The unnamed register "" is a funny thing. It's not really a true register like the others, since text isn't stored there. It's actually a pointer to some other register (usually "- for deletes with no newline, "0 for yanks, or "1 for deletes with a newline). q" breaks the rules; it actually writes to "0. If your "" was already pointing to some register other than "0, q" will overwrite "0 but leave "" unchanged. When you start a fresh Vim, "" automatically points to "0, so you're fine in that case.

Basically, Vim is weird and buggy.

udioica

Posted 2011-01-28T00:34:05.293

Reputation: 2 151

wait why doesn't this work for me – Destructible Lemon – 2016-10-14T07:32:22.580

@DestructibleWatermelon Can't say for sure, but one explanation is most likely. Probably should have had it in the write-up before, since it can throw people off. Read the edit. – udioica – 2016-10-14T08:19:39.377

you should probably put something about how pressing y or something before running can help – Destructible Lemon – 2016-10-14T08:25:26.633

Why don't you use to show pressing the <Esc> key? Part of this Unicode Block “Control Pictures”

– mbomb007 – 2016-10-15T20:25:51.817

2@mbomb007 The &lt;Esc&gt; notation is standard in Vim mappings (:help &lt;&gt;) and that's what vimgolf.com uses. Any experienced vimgolfer will be used to reading it. As for the unicode, I have to squint to read the little letters, and they obscure the method of typing them and searching the help file. – udioica – 2016-10-15T21:44:42.800

Can you explain more? – CalculatorFeline – 2016-10-16T22:19:18.680

35

PostScript, 20 chars

Short and legit. 20 chars including trailing newline.

(dup == =)
dup == =

KirarinSnow

Posted 2011-01-28T00:34:05.293

Reputation: 801

33

Cubix, 20 bytes

3434Qu$v@!<"OOw\o;/"

Almost got the \o/...

Net:

    3 4
    3 4
Q u $ v @ ! < "
O O w \ o ; / "
    . .
    . .

Try it online

Try it here!

Additional notes

Background story

After being impressed by reading this great answer by @ais523, I started thinking about further golfing the quine. After all, there were quite a few no-ops in there, and that didn't feel very compressed. However, as the technique his answer (and mine as well) uses, requires the code to span full lines, a saving of at least 12 bytes was needed. There was one remark in his explanation that really got me thinking:

On the subject of golfing down this quine further, [...] it'd need [...] some other way to represent the top face of the cube [...]

Then, suddenly, as I stood up and walked away to get something to drink, it struck me: What if the program didn't use character codes, but rather numbers to represent the top face? This is especially short if the number we're printing has 2 digits. Cubix has 3 one-byte instructions for pushing double-digit numbers: N, S and Q, which push 10, 32 and 34 respectively, so this should be pretty golfy, I thought.

The first complication with this idea is that the top face is now filled with useless numbers, so we can't use that anymore. The second complication is that the top face has a size which is the cube size squared, and it needed to have an even size, otherwise one number would also end up on the starting position of the instruction pointer, leading to a polluted stack. Because of these complications, my code needed to fit on a cube of size 2 (which can contain 'only' 24 bytes, so I had to golf off at least 21 bytes). Also, because the top and bottom faces are unusable, I only had 16 effective bytes.

So I started by choosing the number that would become half of the top face. I started out with N (10), but that didn't quite work out because of the approach I was taking to print everything. Either way, I started anew and used S (32) for some reason. That did result in a proper quine, or so I thought. It all worked very well, but the quotes were missing. Then, it occured to me that the Q (34) would be really useful. After all, 34 is the character code of the double quote, which enables us to keep it on the stack, saving (2, in the layout I used then) precious bytes. After I changed the IP route a bit, all that was left was an excercise to fill in the blanks.

How it works

The code can be split up into 5 parts. I'll go over them one by one. Note that we are encoding the middle faces in reverse order because the stack model is first-in-last-out.

Step 1: Printing the top face

The irrelevant instructions have been replaced by no-ops (.). The IP starts the the third line, on the very left, pointing east. The stack is (obviously) empty.

    . .
    . .
Q u . . . . . .
O O . . . . . .
    . .
    . .

The IP ends at the leftmost position on the fourth line, pointing west, about to wrap around to the rightmost position on that same line. The instructions executed are (without the control flow character):

QOO
Q   # Push 34 (double quotes) to the stack
 OO # Output twice as number (the top face)

The stack contains just 34, representlng the last character of the source.

Step 2: Encode the fourth line

This bit pretty much does what you expect it to do: encode the fourth line. The IP starts on the double quote at the end of that line, and goes west while pushing the character codes of every character it lands on until it finds a matching double quote. This matching double quote is also the last character on the fourth line, because the IP wraps again when it reaches the left edge.

Effectively, the IP has moved one position to the left, and the stack now contains the representation of the fourth line in character codes and reverse order.

Step 3: Push another quote

We need to push another quote, and what better way than to recycle the Q at the start of the program by approaching it from the right? This has the added bonus that the IP directly runs into the quote that encodes the third line.

Here's the net version for this step. Irrelevant intructions have been replaced by no-ops again, the no-ops that are executed have been replaced by hashtags (#) for illustration purposes and the IP starts at the last character on the fourth line.

    . .
    . .
Q u $ . . . . .
. . w \ . . / .
    . #
    . #

The IP ends on the third line at the first instruction, about to wrap to the end of that line because it's pointing west. The following instructions (excluding control flow) are excecuted:

$uQ
$u  # Don't do anthing
  Q # Push the double quote

This double quote represents the one at the end of the third line.

Step 4: Encoding the third line

This works exactly the same as step 2, so please look there for an explanation.

Step 5: Print the stack

The stack now contains the fourth and third lines, in reverse order, so all we need to do now, it print it. The IP starts at the penultimate instruction on the third line, moving west. Here's the relevant part of the cube (again, irrelevant parts have been replaced by no-ops).

    . .
    . .
. . . v @ ! < .
. . . \ o ; / .
    . .
    . .

This is a loop, as you might have seen/expected. The main body is:

o;
o  # Print top of stack as character
 ; # Delete top of stack

The loop ends if the top item is 0, which only happens when the stack is empty. If the loop ends, the @ is executed, ending the program.

Luke

Posted 2011-01-28T00:34:05.293

Reputation: 4 365

wish I could upvote this more – MickyT – 2017-04-27T02:00:14.597

Bounties are always welcome ;-) – Luke – 2017-04-27T07:23:34.737

32

Python 2, 29 bytes

_='_=%r;print _%%_';print _%_

from en.literateprograms.org

hallvabo

Posted 2011-01-28T00:34:05.293

Reputation: 1 610

1It looks weird with the variable name as _, but reads better if you assign it to any letter, i.e. s: s='s=%r;print s%%s';print s%s – Ehtesh Choudhury – 2015-10-14T16:20:08.627

4If this solution is not your own creation, you should make it Community Wiki. Also, the link is dead. – mbomb007 – 2016-04-27T20:12:03.443

1I'm a bit late to the party, but can someone explain how this works? – MadTux – 2016-10-12T15:31:43.747

@MadTux % is the string formatting operator; in this case, x % y replaces all instances of %r in x with y formatted as a string. The % must be escaped with a second %. – Conor O'Brien – 2016-10-17T17:53:49.403

5This requires a trailing linefeed to be valid. As it is, the source code doesn't match the output. – Dennis – 2017-01-05T17:10:48.243

1+1, you beat my similar solution so I deleted it. It should be noted that this only works in Python 2. – nyuszika7h – 2014-04-28T12:32:32.700

32

Javascript ES6 - 21 bytes

$=_=>`$=${$};$()`;$()

I call this quine "The Bling Quine."

Sometimes, you gotta golf in style.

Mama Fun Roll

Posted 2011-01-28T00:34:05.293

Reputation: 6 535

Does !$=_=&gt;\!$=${$}()`()` save you 2 bytes? – Downgoat – 2016-02-17T06:20:52.313

Invalid assignment left hand side. Wish it worked :( – Mama Fun Roll – 2016-02-17T14:21:11.043

Does !_=&gt;\!$=${$}()`()` work ? – Downgoat – 2016-02-17T16:36:33.167

Declaration of quine is missing. Nope. – Mama Fun Roll – 2016-02-18T01:15:27.887

$=_=&gt;eval(`$=${$};$()`);$() is a rather amusing quine to crash your browser. – Patrick Roberts – 2016-07-29T15:27:24.170

@PatrickRoberts $=_=&gt;eval\$=${$};$()`;$()` Two bytes off – TuxCopter – 2016-10-20T21:38:34.050

@TùxCräftîñg that won't work – Patrick Roberts – 2016-10-20T21:45:01.557

@TùxCräftîñg eliminating parentheses around template literals only works on native prototype functions, like Array.prototype.join. – Mama Fun Roll – 2016-10-21T03:44:31.707

@MamaFunRoll TIL – TuxCopter – 2016-10-21T10:35:40.647

I love this one so much. I don't think it's quite correct, though - the REPL environments I run it in all enclose the output in quotes, and evaluating it with node.js doesn't output anything. Needs a console.log somewhere. – TehShrike – 2017-01-12T21:16:15.030

2Hmm, not sure. I wrote this over a year ago (it was considered valid then), and I haven't been following quine rule changes too closely. However, adding alert or console.log after the arrow function and wrapping the template string in parentheses would work. – Mama Fun Roll – 2017-01-12T22:12:17.230

Also if You run this in the concole, it overwrites $ ( jQuery function ) on this site, and the upvote function won't work anymore. :) – Steven Palinkas – 2017-05-19T11:09:28.193

30

Cubix, 45 bytes

.....>...R$R....W..^".<R.!'.\)!'"R@>>o;?/o'u"

You can test this code here.

This program is fairly hard to follow, but to have any chance to do so, we need to start by expanding it into a cube, like the Cubix interpreter does:

      . . .
      . . >
      . . .
R $ R . . . . W . . ^ "
. < R . ! ' . \ ) ! ' "
R @ > > o ; ? / o ' u "
      . . .
      . . .
      . . .

This is a Befunge-style quine, which works via exploiting wrapping to make string literals "wrap around" executable code (with only one " mark, the code is both inside and outside the quote at the same time, something that becomes possible when you have programs that are nonlinear and nonplanar). Note that this fits our definition of a proper quine, because two of the double quotes don't encode themselves, but rather are calculated later via use of arithmetic.

Unlike Befunge, though, we're using four strings here, rather than one. Here's how they get pushed onto the stack;

  1. The program starts at the top of the left edge, going rightwards; it turns right twice (R), making it go leftwards along the third and last of the lines that wrap around the whole cube. The double quote matches itself, so we push the entire third line onto the stack backwards. Then execution continues after the double quote.

  2. The u command does a U-turn to the right, so the next thing we're running is from '" onwards on the middle line. That pushes a " onto the stack. Continuing to wrap around, we hit the < near the left hand side of the cube and bounce back. When approaching from this direction, we see a plain " command, not '", so the entire second line is pushed onto the stack backwards above the third line and the double quote.

  3. We start by pushing a ! onto the stack ('!) and incrementing it ()); this produces a double quote without needing a double quote in our source code (which would terminate the string). A mirror (\) reflects the execution direction up northwards; then the W command sidesteps to the left. This leaves us going upwards on the seventh column, which because this is a cube, wraps to leftwards on the third row, then downwards on the third column. We hit an R, to turn right and go leftwards along the top row; then the $ skips the R via which we entered the program, so execution wraps round to the " at the end of the line, and we capture the first line in a string the same way that we did for the second and third.

  4. The ^ command sends us northwards up the eleventh column, which is (allowing for cube wrapping) southwards on the fifth. The only thing we encounter there is ! (skip if nonzero; the top of the stack is indeed nonzero), which skips over the o command, effectively making the fifth column entirely empty. So we wrap back to the u command, which once again U-turns, but this time we're left on the final column southwards, which wraps to the fourth column northwards. We hit a double quote during the U-turn, though, so we capture the entire fourth column in a string, from bottom to top. Unlike most double quotes in the program, this one doesn't close itself; rather, it's closed by the " in the top-right corner, meaning that we capture the nine-character string ...>......

So the stack layout is now, from top to bottom: fourth column; top row; "; middle row; "; bottom row. Each of these are represented on the stack with the first character nearest the top of the stack (Cubix pushes strings in the reverse of this order, like Befunge does, but each time the IP was moving in the opposite direction to the natural reading direction, so it effectively got reversed twice). It can be noted that the stack contents are almost identical to the original program (because the fourth column, and the north/top face of the cube, contain the same characters in the same order; obviously, it was designed like that intentionally).

The next step is to print the contents of the stack. After all the pushes, the IP is going northwards on the fourth column, so it hits the > there and enters a tight loop >>o;? (i.e. "turn east, turn east, output as character, pop, turn right if positive"). Because the seventh line is full of NOPs, the ? is going to wrap back to the first >, so this effectively pushes the entire contents of the stack (? is a no-op on an empty stack). We almost printed the entire program! Unfortunately, it's not quite done yet; we're missing the double-quote at the end.

Once the loop ends, we reflect onto the central line, moving west, via a pair of mirrors. (We used the "other side" of the \ mirror earlier; now we're using the southwest side. The / mirror hasn't been used before.) We encounter '!, so we push an exclamation mark (i.e. 33; we're using ASCII and Cubix doesn't distinguish between integers and characters) onto the stack. (Conveniently, this is the same ! which was used to skip over the o command earlier.) We encounter a pair of R commands and use them to make a "manual" U-turn (the second R command here was used earlier in order to reach the first row, so it seemed most natural to fit another R command alongside it.) The execution continues along a series of NOPs until it reaches the W command, to sidestep to the left. The sidestep crashes right into the > command on the second line, bouncing execution back exactly where it was. So we sidestep to the left again, but this time we're going southwards, so the next command to execute is the ) (incrementing the exclamation mark into a double quote), followed by an o (to output it). Finally, execution wraps along the eighth line to the second column, where it finds a @ to exit the program.

I apologise for the stray apostrophe on the third line. It doesn't do anything in this version of the program; it was part of an earlier idea I had but which turned out not to be necessary. However, once I'd got a working quine, I just wanted to submit it rather than mess around with it further, especially as removing it wouldn't change the byte count. On the subject of golfing down this quine further, it wouldn't surprise me if this were possible at 3×3 by only using the first five lines, but I can't see an obvious way to do that, and it'd need even tighter packing of all the control flow together with some other way to represent the top face of the cube (or else modifying the algorithm so that it can continue to use the fourth column even though it'd now be ten or eleven characters long).

user62131

Posted 2011-01-28T00:34:05.293

Reputation:

Nice work, this is a really impressive score. I love how you encoded the top face. :) – Martin Ender – 2016-12-18T08:45:46.120

This is just incredible! If it would help any, another way to push " is Q. – ETHproductions – 2016-12-18T12:24:41.173

1Wow! I never though I'd see a cubix quine! – FlipTack – 2016-12-19T15:28:45.607

3I didn't have time to read the explanation yesterday, but now that I have... Just... WOW. I can't believe how many characters are used for two or even three completely different purposes. This is probably the coolest Cubix program I've ever seen. – ETHproductions – 2016-12-19T16:47:05.070

Good explanation. – Robert Fraser – 2017-03-22T03:28:37.743

28

Hexagony, side length 11, 330 bytes

362003511553420961423766261426252539048636523959468260999944549820033581478284471415809677091006384959302453627348235790194699306179..../:{;+'=1P'%'a{:..\.....................\...................\..................\.................\................\...............\..............\.............\!$><........\..@>{?2'%<......:;;4Q/

Try it online!

Encoder: Try it online!

The program is roughly equivalent to this Python code: Try it online!

Unfolded code:

           3 6 2 0 0 3 5 1 1 5 5
          3 4 2 0 9 6 1 4 2 3 7 6
         6 2 6 1 4 2 6 2 5 2 5 3 9
        0 4 8 6 3 6 5 2 3 9 5 9 4 6
       8 2 6 0 9 9 9 9 4 4 5 4 9 8 2
      0 0 3 3 5 8 1 4 7 8 2 8 4 4 7 1
     4 1 5 8 0 9 6 7 7 0 9 1 0 0 6 3 8
    4 9 5 9 3 0 2 4 5 3 6 2 7 3 4 8 2 3
   5 7 9 0 1 9 4 6 9 9 3 0 6 1 7 9 . . .
  . / : { ; + ' = 1 P ' % ' a { : . . \ .
 . . . . . . . . . . . . . . . . . . . . \
  . . . . . . . . . . . . . . . . . . . \ 
   . . . . . . . . . . . . . . . . . . \  
    . . . . . . . . . . . . . . . . . \   
     . . . . . . . . . . . . . . . . \    
      . . . . . . . . . . . . . . . \     
       . . . . . . . . . . . . . . \      
        . . . . . . . . . . . . . \       
         ! $ > < . . . . . . . . \        
          . . @ > { ? 2 ' % < . .         
           . . . . : ; ; 4 Q / .          

Two .s takes 1 bit. Any other characters take 1 bit and a base-97 digit.

Explanation

Click at the images for larger size. Each explanation part has corresponding Python code to help understanding.

Data part

Instead of the complex structure used in some other answers (with <, " and some other things), I just let the IP pass through the lower half.

Data

First, the IP runs through a lot of numbers and no-op's (.) and mirrors (\). Each digit appends to the number in the memory, so in the end the memory value is equal to the number at the start of the program.

mem = 362003511...99306179

! prints it,

stdout.write(str(mem))

and $ jumps through the next >.

Starting from the <. If the memory value mem is falsy (<= 0, i.e., the condition mem > 0 is not satisfied), we have done printing the program, and should exit. The IP would follow the upper path.

Exit

(let the IP runs around the world for about 33 commands before hitting the @ (which terminates the program) because putting it anywhere else incurs some additional bytes)

If it's true, we follow the lower path, get redirected a few times and execute some more commands before hitting another conditional.

# Python                    # Hexagony
# go to memory cell (a)     # {
a = 2                       # ?2
# go to memory cell (b)     # '
b = mem % a                 # %

Now the memory looks like this:

Mem1

If the value is truthy:

if b > 0:

the following code is executed:

# Python                    # Hexagony
b = ord('Q')                # Q
b = b*10+4                  # 4
# Note: now b == ord('.')+256*3
stdout.write(chr(b%256))    # ;
stdout.write(chr(b%256))    # ;

See detailed explanation of the Q4 at MartinEnder's HelloWorld Hexagony answer. In short, this code prints . twice.

Originally I planned for this to print . once. When I came up with this (print . twice) and implement it, about 10 digits were saved.

Then,

b = mem // a                # :

Here is a important fact I realized that saved me about 14 digits: You don't need to be at where you started.


To understand what I'm saying, let's have a BF analogy. (skip this if you already understood)

Given the code

while a != 0:
    b, a = a * 2, 0
    a, b = b, 0
    print(a)

Assuming we let a be the value of the current cell and b be the value of the right cell, a straightforward translation of this to BF is:

[             # while a != 0:
    [->++<]       # b, a = a * 2, 0
    >[-<+>]       # a, b = b, 0
    <.            # print(a)
]

However, note that we don't need to be at the same position all the time during the program. We can let the value of a be whatever we are at the start of each iteration, then we have this code:

[             # while a != 0:
    [->++<]       # b, a = a * 2, 0
                  # implicitly let (a) be at the position of (b) now
    .             # print(a)
]

which is several bytes shorter.


Also, the corner wrapping behavior also saves me from having a \ mirror there - without it I would not be able to fit the digits (+2 digits for the \ itself and +2 digits for an unpaired . to the right of it, not to mention the flags)

(details:

  • The IP enters the lower-left corner, heading left
  • It get warped to the right corner, still heads left
  • It encounters a \ which reflects it, now it heads right-up
  • It goes into the corner and get warped again to the lower-left corner

)


If the value (of the mod 2 operation above) is falsy (zero), then we follow this path:

# Python                 # Hexagony   # Memory visualization after execution
b = mem // a             # :          # click here
base = ord('a') # 97     # a
y = b % base             # '%
offset = 33              # P1
z = y + offset           # ='+
stdout.write(chr(z))     # ;          # click here
mem = b // base          # {:         # click here

I won't explain too detailed here, but the offset is actually not exactly 33, but is congruent to 33 mod 256. And chr has an implicit % 256.

user202729

Posted 2011-01-28T00:34:05.293

Reputation: 7 149

3Man, that is a lot of no-ops – Jo King – 2018-02-21T08:02:23.510

7I laughed at "To understand what I'm saying, let's have a [BrainFuck] analogy." Only on PPCG... :) – Lynn – 2018-02-23T16:52:20.120

1I scrolled like 3 times to the top of the answer to upvote it, only to find out that I did it already... – NieDzejkob – 2018-02-23T16:56:30.460

28

Vim, 17, 14 keystrokes

Someone randomly upvoted this, so I remembered that it exists. When I re-read it, I thought "Hey, I can do better than that!", so I golfed two bytes off. It's still not the shortest, but at least it's an improvement.


For a long time, I've been wondering if a vim quine is possible. On one hand, it must be possible, since vim is turing complete. But after looking for a vim quine for a really long time, I was unable to find one. I did find this PPCG challenge, but it's closed and not exactly about literal quines. So I decided to make one, since I couldn't find one.

I'm really proud of this answer, because of two firsts:

  1. This is the first quine I have ever made, and

  2. As far as I know, this is the worlds first vim-quine to ever be published! I could be wrong about this, so if you know of one, please let me know.

So, after that long introduction, here it is:

qqX"qpAq@q<esc>q@q

Try it online!

Note that when you type this out, it will display the <esc> keystroke as ^[. This is still accurate, since ^[ represents 0x1B, which is escape in ASCII, and the way vim internally represents the <esc> key.

Also note, that testing this might fail if you load an existing vim session. I wrote a answer explaining that here, if you want more information, but basically you need to launch vim with

vim -u NONE -N -i NONE

or type qqq before running this.

Explanation:

qq                  " Start recording into register 'q'
  X                 " Delete one character before the cursor (Once we play this back, it will delete the '@')
   "qp              " Paste register 'q'
      Aq@q<esc>     " Append 'q@q' to this line
               q    " Stop recording
                @q  " Playback register 'q'

On a side note, this answer is probably a world record for most 'q's in a PPCG answer, or something.

DJMcMayhem

Posted 2011-01-28T00:34:05.293

Reputation: 37 405

9+1 for amazingness 10/10 – Downgoat – 2016-09-09T00:58:20.750

12i2i&lt;esc&gt; is so close. I feel like there must be something I can do to make this work. – Zwei – 2016-10-01T20:41:08.353

@zwei I know, it's close it hurts! Actually, &lt;Esc&gt; is implicit in V, so that works. Unfortunately it also adds a newline, which is why I haven't posted it yet.

– DJMcMayhem – 2016-10-01T20:43:37.787

q"iq"qbP&lt;Esc&gt;qbP is 11. After you put this on reddit, I investigated the vimgolfing here and decided to make an account. This is the answer I posted there. – udioica – 2016-10-11T12:49:19.107

2@udioica Can you post that as an answer? – DJMcMayhem – 2016-10-11T12:59:19.230

27

Hexagony, side length 15 14 13 12, 616 533 456 383 bytes

After several days of careful golfing, rearranging loops and starting over, I've finally managed to get it down to a side 12 hexagon.

1845711724004994017660745324800783542810548755533855003470320302321248615173041097895645488030498537186418612923408209003405383437728326777573965676397524751468186829816614632962096935858"">./<$;-<.....>,.........==.........<"......."">'....>+'\.>.........==........<"......"">:>)<$=<..>..............$..<"...."">\'Q4;="/@>...............<"....."">P='%<.>.............<"..!'<.\=6,'/>

Try it online!

Unfolded:

            1 8 4 5 7 1 1 7 2 4 0 0
           4 9 9 4 0 1 7 6 6 0 7 4 5
          3 2 4 8 0 0 7 8 3 5 4 2 8 1
         0 5 4 8 7 5 5 5 3 3 8 5 5 0 0
        3 4 7 0 3 2 0 3 0 2 3 2 1 2 4 8
       6 1 5 1 7 3 0 4 1 0 9 7 8 9 5 6 4
      5 4 8 8 0 3 0 4 9 8 5 3 7 1 8 6 4 1
     8 6 1 2 9 2 3 4 0 8 2 0 9 0 0 3 4 0 5
    3 8 3 4 3 7 7 2 8 3 2 6 7 7 7 5 7 3 9 6
   5 6 7 6 3 9 7 5 2 4 7 5 1 4 6 8 1 8 6 8 2
  9 8 1 6 6 1 4 6 3 2 9 6 2 0 9 6 9 3 5 8 5 8
 " " > . / < $ ; - < . . . . . > , . . . . . .
  . . . = = . . . . . . . . . < " . . . . . .
   . " " > ' . . . . > + ' \ . > . . . . . .
    . . . = = . . . . . . . . < " . . . . .
     . " " > : > ) < $ = < . . > . . . . .
      . . . . . . . . . $ . . < " . . . .
       " " > \ ' Q 4 ; = " / @ > . . . .
        . . . . . . . . . . . < " . . .
         . . " " > P = ' % < . > . . .
          . . . . . . . . . . < " . .
           ! ' < . \ = 6 , ' / > . .
            . . . . . . . . . . . .

While it doesn't look like the most golfed of Hexagony code, the type of encoding I used is optimised for longer runs of no-ops, which is something you would otherwise avoid.

Explanation

This beats the previous Hexagony answer by encoding the no-ops (.) in a different way. While that answer saves space by making every other character a ., mine encodes the number of no-ops. It also means the source doesn't have to be so restricted.

Here I use a base 80 encoding, where numbers below 16 indicate runs of no-ops, and numbers between 16 and 79 represent the range 32 (!) to 95 (_) (I'm just now realising I golfed all the _s out of my code lol). Some Pythonic pseudocode:

i = absurdly long number
print(i)
base = 80
n = i%base
while n:
    if n < 16:
        print("."*(16-n))
    else:
        print(ASCII(n+16))
    i = i//base
    n = i%base

The number is encoded in the first half of the hexagon, with all the

" " > 
 " " > 
  ... etc

on the left side and the

 > ,
< "
 >
< "
... etc

on the right side redirecting the pointer to encode the number into one cell. This is taken from Martin Ender's answer (thanks), because I couldn't figure out a more efficient way.

It then enters the bottom section through the ->:

       " " > \ ' Q 4 ; = " / @ > . . . .
        . . . . . . . . . . . < " . . .
         . . " " > P = ' % < . > . . .
          . . . . . . . . . . < " . .
     ->    ! ' < . \ = 6 , ' / > . .

! prints the number and ' navigates to the right memory cell before starting the loop. P='% mods the current number by 80. If the result is 0, go up to the terminating @, else go down and create a cell next to the mod result with the value -16.

   . " " > ' . . . . > + ' \ . > . . . . . .
    . . . = = . . . . . . . . < " . . . . .
     . " " > : > ) < $ = < . . > . . . . .
      . . . . . . . . . $ . . < " . . . .
       " " > \ ' Q 4 ; = " / @ > . . . .
                      /
                     /

Set the cell to (mod value + -16). If that value is negative, go up at the branching >+'\, otherwise go down.

If the value is positive:

 " " > . / < $ ; - < . . . . . > , . . . . . .
  . . . = = . . . . . . . . . < " . . . . . .
   . " " > ' . . . . > + ' \ . > . . . . . .

The pointer ends up at the ;-< which sets the cell to (mod value - -16) and print it.

The the value is negative:

   . " " > ' . . . . > + ' \ . > . . . . . .
    . . . = = . . . . . . . . < " . . . . .
     . " " > : > ) < $ = < . . > . . . . .

Go down to the > ) < section which starts the loop. Here it is isolated:

     . . > ) < $ = < . .
      . . . . . . . . .
       \ ' Q 4 ; = " /

Which executes the code 'Q4;="= which prints a . (thanks again to Martin Ender, who wrote a program to find the letter-number combinations for characters) and moves back to the starting cell. It then increments ()) the mod value cell and loops again, until the mod value is positive.

When that is done, it moves up and joins with the other section at:

 " " > . / < $ ; - < . . .
            \
             \

The pointer then travels back to the start of the larger loop again

 " " > . / <--
  . . . = =
   . " " > ' 
    . . . = = 
     . " " > :
      . . . . .
       " " > \ ' . .
        . . . . . . .
         . . " " > P = ' % < . > . . .

This executes ='=:' which divides the current number by 80 and navigates to the correct cell.

Old version (Side length 13)

343492224739614249922260393321622160373961419962223434213460086222642247615159528192623434203460066247203920342162343419346017616112622045226041621962343418346002622192616220391962343417346001406218603959366061583947623434"">/':=<$;'<.....>(......................<"......"">....'...>=\..>.....................<"....."">....>)<.-...>...........==......<"...."">.."...'.../>.................<"..."">\Q4;3=/.@.>...............<".."".>c)='%<..>..!'<.\1*='/.\""

Try it online!

I can most definitely golf another side length off this, but I'll have to leave it til' tomorrow because it's getting late. Turns out I'm impatient and can't wait until tomorrow. Maybe another side can be golfed? :( ahhhhhhhhh i did it!

I even golfed off a couple of extra digits with a base 77 encoding, but it doesn't really matter, since it has the same bytecount.

Jo King

Posted 2011-01-28T00:34:05.293

Reputation: 5 911

12This is amazing. The idea for this hybrid run-length encoding is really neat. :) Remind me to give you a bounty if I forget. – Martin Ender – 2018-02-10T12:03:43.930

25

Fission, 6 bytes

It appears this is now the shortest "proper" quine among these answers. However, Fission is only a bit over a year old, so this answer is technically not eligible for being accepted. Then again, I highly doubt that Fission was specifically written to make quining easy.

'!+OR"

Explanation

Control flow starts at R with a single right-going (1,0) atom. It hits " toggling print mode and then wraps around the line, printing '!+OR before hitting the same " again and exiting print mode.

That leaves the " itself to be printed. The shortest way is '"O (where '" sets the atom's mass to the character code of " and O prints the character and destroys the atom), but if we did this the " would interfere with print mode. So instead we set the atom's value to '! (one less than "), then increment with + and then print the result with O.

Alternatives

Here are a couple of alternatives, which are longer, but maybe their techniques inspire someone to find a shorter version using them (or maybe they'll be more useful in certain generalised quines).

8 bytes using Jump

' |R@JO"

Again, the code starts at R. The @ swaps mass and energy to give (0,1). Therefore the J makes the atom jump over the O straight onto the ". Then, as before, all but the " are printed in string mode. Afterwards, the atom hits | to reverse its direction, and then passes through '"O printing ". The space is a bit annoying, but it seems necessary, because otherwise the ' would make the atom treat the | as a character instead of a mirror.

8 bytes using two atoms

"'L;R@JO

This has two atoms, starting left-going from L and right-going from R. The left-going atom gets its value set by '" which is then immediately printed with O (and the atom destroyed). For the right-going atom, we swap mass and energy again, jump over the O to print the rest of the code in print mode. Afterwards its value is set by 'L but that doesn't matter because the atom is then discarded with ;.

Martin Ender

Posted 2011-01-28T00:34:05.293

Reputation: 162 549

Technically invalid due to lack of code/data separation in the source. – CalculatorFeline – 2017-01-05T02:24:47.600

2@CalculatorFeline '!+ encodes ". – Martin Ender – 2017-01-05T08:51:32.933

I'm not familiar with Fission, but would |R@JO"' work, or would you still need that space after the '? – Mistah Figgins – 2017-03-06T01:34:38.927

1@MistahFiggins I think so, but more importantly you'd print the ' first. – Martin Ender – 2017-03-06T07:06:53.053

24

These are the two shortest Ruby quines from SO:

_="_=%p;puts _%%_";puts _%_

and

puts <<2*2,2
puts <<2*2,2
2

Don't ask me how the second works...

Nakilon

Posted 2011-01-28T00:34:05.293

Reputation: 595

8The second one uses heredoc, &lt;&lt;2 starts a string on the next line, and *2 repeats the string – Ming-Tang – 2011-01-28T02:52:04.640

Why do you need the 2? – CalculatorFeline – 2016-03-07T05:27:09.660

@CalculatorFeline It's the terminator of the heredoc string (which has to appear on its own line). It doesn't actually have to be a 2 though: https://tio.run/##KypNqvz/v6C0pFjBxsZAy0jHgAuFY8D1/z8A

– Martin Ender – 2018-03-02T08:47:51.877

22

Chicken, 7

chicken

No, this is not directly echoed :)

Timtech

Posted 2011-01-28T00:34:05.293

Reputation: 11 060

It's not echoed, it's the string chicken! – Erik the Outgolfer – 2016-06-28T21:45:51.840

No code/data separation, and therefore invalid. – CalculatorFeline – 2017-01-05T02:25:50.243

7@CalculatorFeline Did you read the rules? – Timtech – 2017-01-05T15:36:11.373

By the current quine definition this is not valid, as it should be possible to identify a section of the program which encodes a different part of the program. chicken appears to encode only chicken and nothing else.

– Jo King – 2018-02-20T00:45:34.863

Damnit, you beat me to it :) – Taconut – 2014-02-01T22:42:35.580

22

Java, 528 bytes:

A Java solution with an original approach:

import java.math.*;class a{public static void main(String[]a){BigInteger b=new BigInteger("90ygts9hiey66o0uh2kqadro71r14x0ucr5v33k1pe27jqk7mywnd5m54uypfrnt6r8aks1g5e080mua80mgw3bybkp904cxfcf4whcz9ckkecz8kr3huuui5gbr27vpsw9vc0m36tadcg7uxsl8p9hfnphqgksttq1wlolm2c3he9fdd25v0gsqfcx9vl4002dil6a00bh7kqn0301cvq3ghdu7fhwf231r43aes2a6018svioyy0lz1gpm3ma5yrspbh2j85dhwdn5sem4d9nyswvx4wmx25ulwnd3drwatvbn6a4jb000gbh8e2lshp",36);int i=0;for(byte c:b.toByteArray()){if(++i==92)System.out.print(b.toString(36));System.out.print((char)c);}}}

in readable form:

import java.math.*;
class a
{
    public static void main (String [] a)
    {
        BigInteger b=new BigInteger ("90ygts9hiey66o0uh2kqadro71r14x0ucr5v33k1pe27jqk7mywnd5m54uypfrnt6r8aks1g5e080mua80mgw3bybkp904cxfcf4whcz9ckkecz8kr3huuui5gbr27vpsw9vc0m36tadcg7uxsl8p9hfnphqgksttq1wlolm2c3he9fdd25v0gsqfcx9vl4002dil6a00bh7kqn0301cvq3ghdu7fhwf231r43aes2a6018svioyy0lz1gpm3ma5yrspbh2j85dhwdn5sem4d9nyswvx4wmx25ulwnd3drwatvbn6a4jb000gbh8e2lshp", 36); 
        int i=0; 
        for (byte c:b.toByteArray ())
        {
            if (++i==92) 
                System.out.print (b.toString (36)); 
            System.out.print ((char) c);
        }
    }
}

user unknown

Posted 2011-01-28T00:34:05.293

Reputation: 3 908

How does it work? – Loovjo – 2015-05-23T13:02:47.513

@Loovjo: Similar as other solutions which cut the code in two parts and inserts the whole String which reprensents the code inside again, but the whole code is not just a String but encoded as the long number in base 36 (26 alphabetical characters + 10 digits). – user unknown – 2015-05-24T09:38:57.877

1This could be shortened if you put if(++i==92), – tuskiomi – 2017-06-12T14:00:55.617

2@tuskiomi: Thanks, shortened for two characters – user unknown – 2017-06-12T14:20:01.910

I see one can save another character by (String a*) instead of (String []a), but then I would have to recompute the magic number, so I guess you get the point. :) – user unknown – 2018-01-23T22:32:02.803

22

Cross-browser JavaScript (41 characters)

It works in the top 5 web browsers (IE >= 8, Mozilla Firefox, Google Chrome, Safari, Opera). Enter it into the developer's console in any one of those:

eval(I="'eval(I='+JSON.stringify(I)+')'")

It's not "cheating" — unlike Chris Jester-Young's single-byte quine, as it could easily be modified to use the alert() function (costing 14 characters):

alert(eval(I="'alert(eval(I='+JSON.stringify(I)+'))'"))

Or converted to a bookmarklet (costing 22 characters):

javascript:eval(I="'javascript:eval(I='+JSON.stringify(I)+')'")

PleaseStand

Posted 2011-01-28T00:34:05.293

Reputation: 4 519

20

Retina, 20 14 9 7 bytes

Before we get started, I'd like to mention the trivial solution of a file which contains a single 0. In that case Retina will try to count the 0s in the empty input, the result of which is also 0. I wouldn't consider that a proper quine though.

So here is a proper one:

>\`
>\`

Try it online!

Alternatively, we could use ; instead of >.

Explanation

The program consists of a single replacement which we print twice.

In the first line, the ` separates the configuration from the regex, so the regex is empty. Therefore the empty string (i.e. the non-existent input) is replaced with the second line, verbatim.

To print the result twice, we wrap it in two output stages. The inner one, \ prints the result with a trailing linefeed, and the outer one, >, prints it without one.

If you're a bit familiar with Retina, you might be wondering what happened to Retina's implicit output. Retina's implicit output works by wrapping the final stage of a program in an output stage. However, Retina doesn't do this, if the final stage is already an output stage. The reason for that is that in a normal program it's more useful to be able to replace the implicit output stage with special one like \ or ; for a single byte (instead of having to get rid of the implicit one with the . flag as well). Unfortunately, this behaviour ends up costing us two bytes for the quine.

Martin Ender

Posted 2011-01-28T00:34:05.293

Reputation: 162 549

19

C, 64 60 bytes

main(s){printf(s="main(s){printf(s=%c%s%1$c,34,s);}",34,s);}

So far, this is the shortest known C quine. There's an extended bounty if you find a shorter one.

This works in GCC, Clang, and TCC in a POSIX environment. It invokes an excessive amount of undefined behavior with all of them.

Just for fun, here's a repo that contains all the C quines I know of. Feel free to fork/PR if you find or write a different one that adds something new and creative over the existing ones.

Note that it only works in an ASCII environment. This works for EBCDIC, but still requires POSIX. Good luck finding a POSIX/EBCDIC environment anyway :P


How it works:

  1. main(s) abuses main's arguments, declaring a virtually untyped variable s. (Note that s is not actually untyped, but since listed compilers auto-cast it as necessary, it might as well be*.)
  2. printf(s="..." sets s to the provided string and passes the first argument to printf.
  3. s is set to main(s){printf(s=%c%s%1$c,34,s);}.
  4. The %c is set to ASCII 34, ". This makes the quine possible. Now s looks like this:
    main(s){printf(s="%s%1$c,34,s);}.
  5. The %s is set to s itself, which is possible due to #2. Now s looks like this:
    main(s){printf(s="main(s){printf(s=%c%s%1$c,34,s);}%1$c,34,s);}.
  6. The %1$c is set to ASCII 34 ", printf's first** argument. Now s looks like this:
    main(s){printf(s="main(s){printf(s=%c%s%1$c,34,s);}",34,s);}
    ... which just so happens to be the original source code.

* Example thanks to @Pavel
** first argument after the format specifier - in this case, s. It's impossible to reference the format specifier.


I think it's impossible that this will get any shorter with the same approach. If printf's format specifier was accessible via $, this would work for 52 bytes:

main(){printf("main(){printf(%c%0$s%1$c,34);}",34);}

MD XF

Posted 2011-01-28T00:34:05.293

Reputation: 8 337

Although it certainly shouldn't count as competing, the winner of "Worst abuse of the rules" from the 1994 International Obfuscated C Code Contest, 1994_smr.c, is definitely shorter.

– Ray – 2017-05-31T19:59:58.570

@Ray It's not allowed. It's not a proper quine by any definition. The quien rules were changed because of that program :P – MD XF – 2017-05-31T20:00:49.213

I agree entirely, but it's an interesting enough hack that it's worth mentioning any time someone mentions a smallest known quine, if only for historical reasons. – Ray – 2017-05-31T20:10:45.820

@Ray Well... smallest known valid quine, anyway. – MD XF – 2017-05-31T20:11:38.947

4s is of type int, not an "untyped variable". – feersum – 2017-07-22T05:32:58.903

1These compilers all apparently allow implicit conversion of a pointer to an int. s=3 obviously wouldn't work because you need to pass the string twice to printf. – feersum – 2017-07-22T19:09:20.540

@jxh I added everything from the nyx.net list, and I'll add Adam's. Thanks! – MD XF – 2017-12-07T00:34:42.097

@jxh I wouldn't consider an EBCDIC-only solution worthy of the bounty for beating this quine, but I'd add one to the repo with a note. – MD XF – 2017-12-07T01:58:46.380

@jxh Well, this quine (the 60-byter) is ASCII/EBCDIC-independent, so I think it's safe. For the repo, I'll clarify that. – MD XF – 2017-12-07T02:04:53.480

@jxh Additionally, I've clarified the bounty.

– MD XF – 2017-12-07T02:07:56.223

@jxh Oh, I do use ASCII codes! I completely forgot... sorry about that. I've edited the answer. – MD XF – 2017-12-07T02:32:00.530

18

Lost, 120 116 98 96 76 70 bytes

Edit: yay, under 100

Edit: Saved a bunch o' bytes by switching to all /s on the bottom line

:2+52*95*2+>1?::::[[[[[@>/?%>(([ "
//////////////////////////////////

Try it online! + verification it's a quine for all possible states

Lost is a 2D language in which the starting position and direction are completely random. This means there has to be a lot of error-checking at every stage to make sure you've got the correct instruction pointer, and it isn't one that has just wandered in off the street.

Explanation:

All the /s on the bottom line are there to make sure that all the pointers that spawn in a vertical direction or on the bottom line get funneled in the right direction. From there, they end up at several different places, but all of them end up going right into the

 /?%>
 ////

Which clears out all the non-zero numbers in the stack. The (([ after that clears out any extra 0s as well.

In the middle of the clear, it hits the %, which turns the 'safety' off, which allows the program to end when it hits the @ (without this, the program could end immediately if a pointer started at the @).

From there it does a pretty simple 2D language quine, by wrapping a string literal (") around the first line, pushing a " character (:2+) and a newline (52*). For the second line, it creates a / character (95*2+) and duplicates it a bunch (>1?::::[[[[[), before finally ending at the @ and printing the stack implicitly. The 1? is to stop the process from creating too many 0s if the pointer enters early, saving on having to clear them later.

I saved 20 bytes here by making the last line all the same character, meaning I could go straight from the duping process into the ending @.

Explanation about the duping process:

(this isn't as informative now that I only have one simple dupe in the program, but i'll leave it in)

[ is a character known as a 'Door'. If the pointer hits the flat side of a [ or a ] , it reflects, else it passes through it. Each time the pointer interacts with a Door, it switches to the opposite type. Using this knowledge we can construct a simple formula for how many times an instruction will execute in a >:[ block.

Add the initial amount of instructions. For each [, add 2 times the amount of instructions to the left of it. For the example >::::[:[[[, we start with 5 as the initial amount. The first Door has 4 dupe instructions, so we add 4*2=8 to 5 to get 13. The other three Doors have 5 dupes to their left, so we add 3*(5*2)=30 to 13 to get 43 dupe instructions executed, and have 44 >s on the stack. The same process can be applied to other instructions, such as ( to push a large amount of items from the stack to the scope, or as used here, to clear items from the stack.

Old version

48*2+52*:6*>:::::[[[[+2-+$::3+$@>((((([[[[[>%\"
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<v<?<

Try it online! + verification it's a quine for all possible states

Jo King

Posted 2011-01-28T00:34:05.293

Reputation: 5 911

18

Javascript (36 char)

(function a(){alert("("+a+")()")})()

This is, AFAICT, the shortest javascript quine posted so far.

Peter Olson

Posted 2011-01-28T00:34:05.293

Reputation: 5 879

7To be pedantic, though, this is only a quine if your JavaScript implementation stringifies the function a exactly the same way as it's been written above. However, the output of this code is likely to be a quine on any JavaScript implementation. – Ilmari Karonen – 2012-02-03T18:55:03.267

1Here is the same quine, 1 byte shorter: !function a(){alert("!"+a+"()")}(). – Ismael Miguel – 2015-02-27T01:22:41.127

@IlmariKaronen Sorry to interrupt, but this is a way to read your own source code! – Erik the Outgolfer – 2016-06-15T08:13:27.717

Same, but output to console: (function a(){return "("+a+")()"})() – Elist – 2017-02-18T21:34:24.850

With lambda (a=()=&gt;alert('('+a+')'))(); – Dennis C – 2017-05-22T05:35:16.187

(a=()=&gt;alert((${a})))() – Dennis C – 2017-05-22T05:40:51.270

@IlmariKaronen not exactly. If an other implementation chooses to add a space between the arguments and the body, the output is not a quine in an implementation that doesn't add a space between the arguments and body. – Johannes Kuhn – 2013-12-21T20:59:21.210

@JohannesKuhn: I meant that, for any given JavaScript implementation, the output of running the above code on that implementation is likely to be a quine on that implementation. Sorry for the imprecise language. – Ilmari Karonen – 2013-12-21T21:22:09.017

Ok, "However, the output of this code is likely to be a quine on that JavaScript implementation." – Johannes Kuhn – 2013-12-21T21:43:31.820

That... is impressive. You should explain how it works for me 8-| – TehShrike – 2011-09-27T19:18:19.643

3@TehShrike Hint: you can view the contents a function by coercing it to a string. For example, if you have a function a, you can access its contents by calling a.toString. – Peter Olson – 2011-09-27T19:22:01.147

18

Labyrinth, 124 110 53 bytes

Thanks to Sp3000 for golfing off 9 bytes, which allowed me to golf off another 7.

44660535853919556129637653276602333!
1
:_98
/8 %
@9_.

Try it online!

Explanation

Labyrinth 101:

  • Labyrinth is a stack-based 2D language. The stack is bottomless and filled with zeroes, so popping from an empty stack is not an error.
  • Execution starts from the first valid character (here the top left). At each junction, where there are two or more possible paths for the instruction pointer (IP) to take, the top of the stack is checked to determine where to go next. Negative is turn left, zero is go forward and positive is turn right.
  • Digits in the source code don't push the corresponding number – instead, they pop the top of the stack and push n*10 + <digit>. This allows the easy building up of large numbers. To start a new number, use _, which pushes zero.
  • " are no-ops.

First, I'll explain a slightly simpler version that is a byte longer, but a bit less magical:

395852936437949826992796242020587432!
"
:_96
/6 %
@9_.

Try it online!

The main idea is to encode the main body of the source in a single number, using some large base. That number can then itself easily be printed back before it's decoded to print the remainder of the source code. The decoding is simply the repeated application of divmod base, where print the mod and continue working with the div until its zero.

By avoiding {}, the highest character code we'll need is _ (95) such that base 96 is sufficient (by keeping the base low, the number at the beginning is shorter). So what we want to encode is this:

!
"
:_96
/6 %
@9_.

Turning those characters into their code points and treating the result as a base-96 number (with the least-significant digit corresponding to ! and the most-significant one to ., because that's the order in which we'll disassemble the number), we get

234785020242697299628949734639258593

Now the code starts with a pretty cool trick (if I may say so) that allows us to print back the encoding and keep another copy for decoding with very little overhead: we put the number into the code in reverse. I computed the result with this CJam script So let's move on to the actual code. Here's the start:

395852936437949826992796242020587432!
"

The IP starts in the top left corner, going east. While it runs over those digits, it simply builds up that number on top of the stack. The number itself is entirely meaningless, because it's the reverse of what we want. When the IP hits the !, that pops this number from the stack and prints it. That's all there is to reproducing the encoding in the output.

But now the IP has hit a dead end. That means it turns around and now moves back west (without executing ! again). This time, conveniently, the IP reads the number from back to front, so that now the number on top of the stack does encode the remainder of the source.

When the IP now hits the top left corner again, this is not a dead end because the IP can take a left turn, so it does and now moves south. The " is a no-op, that we need here to separate the number from the code's main loop. Speaking of which:

...
"
:_96
/6 %
@9_.

As long as the top of the stack is not zero yet, the IP will run through this rather dense code in the following loop:

"
>>>v
^< v
 ^<<

Or laid out linearly:

:_96%._96/

The reason it takes those turns is because of Labyrinth's control flow semantics. When there are at least three neighbours to the current cell, the IP will turn left on a negative stack value, go ahead on a zero and turn right on a positive stack value. If the chosen direction is not possible because there's a wall, the IP will take the opposite direction instead (which is why there are two left turns in the code although the top of the stack is never negative).

The loop code itself is actually pretty straightforward (compressing it this tightly wasn't and is where Sp3000's main contribution is):

:    # Duplicate the remaining encoding number N.
_96  # Push 96, the base.
%.   # Take modulo and print as a character.
_96  # Push 96 again.
/    # Divide N by 96 to move to the next digit.

Once N hits zero, control flow changes. Now the IP would like to move straight ahead after the / (i.e. west), but there's a wall there. So instead if turns around (east), executes the 6 again. That makes the top of the stack positive, so the IP turns right (south) and executes the 9. The top of the stack is now 69, but all we care about is that it's positive. The IP takes another right turn (west) and moves onto the @ which terminates the code.

All in all, pretty simple actually.

Okay, now how do we shave off that additional byte. Clearly, that no-op seems wasteful, but we need that additional row: if the loop was adjacent to the number, the IP would already move there immediately instead of traversing the entire number. So can we do something useful with that no-op.

Well, in principle we can use that to add the last digit onto the encoding. The encoding doesn't really need to be all on the first line... the ! just ensures that whatever is there also gets printed there.

There is a catch though, we can't just do this:

95852936437949826992796242020587432!
3
:_96
/6 %
@9_.

The problem is that now we've changed the " to a 3, which also changes the actual number we want to have. And sure enough that number doesn't end in 3. Since the number is completely determined by the code starting from ! we can't do a lot about that.

But maybe we can choose another digit? We don't really care whether there's a 3 in that spot as long as we end up with a number that correctly encodes the source. Well, unfortunately, none of the 10 digits yields an encoding whose least-significant digit matches the chosen one. Luckily, there's some leeway in the remainder of the code such that we can try a few more encodings without increasing the byte count. I've found three options:

  1. We can change @ to /. In that case we can use any digit from 1357 and get a matching encoding. However, this would mean that the program then terminates with an error, which is allowed but doesn't seem very clean.
  2. Spaces aren't the only "wall" characters. Every unused character is, notably all letters. If we use an upper case letter, then we don't even need to increase the base to accommodate it (since those code points are below _). 26 choices gives plenty of possibilities. E.g. for A any odd digit works. This is a bit nicer, but it still doesn't seem all that elegant, since you'd never use a letter there in real code.
  3. We can use a greater base. As long as we don't increase the base significantly, the number of decimal digits in the encoding will remain the same (specifically, any base up to 104 is fine, although bases beyond 99 would actually require additional characters in the code itself). Luckily, base 98 gives a single matching solution: when we use the digit 1, the encoding also ends in 1. This is the only solution among bases 96, 97, 98, 99, so this is indeed very lucky. And that's how we end up with the code at the top of this answer.

Martin Ender

Posted 2011-01-28T00:34:05.293

Reputation: 162 549

16

Lost, 293 262 249 bytes

>:2+52*:6*:(84*+75*):>:::::[[[[[[[:[(52*)>::::[[[[[[:[84*+@>%?!<((((((((((([[[[[[[[[[[[[[ "
\#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\

Try it online!

Explanation

This entire project has been an up and down. I kept thinking it was impossible and then coming up with a crazy idea that just might work.

Why is a Lost Quine so hard?

As you may know Lost is a 2D programming language where the start location and direction are entirely random. This makes writing any lost program about as difficult as writing radiation hardened code. You have to consider every possible location and direction.

That being said there are some standard ways to do things. For example here is the standard way of printing a string.

>%?"Stringv"(@
^<<<<<<<<<<<<<

This has a collection stream at the bottom that grabs the most of the ips and pulls them to the start location. Once they reach are start location (upper left) we sanitize them with a loop getting rid of all the values on the stack then turn the safety of push the string and exit. (safety is a concept unique to Lost every program must hit a % before exiting, this prevents the possibility of the program terminating upon start). Now my idea would be to extend this form into a full fledged quine.

The first thing that had to be done was to rework the loop a bit, the existing loop was specific to the String format.

>%?!<"Stringv"(@
^<<<<<<<<<<<<<<<
^<<<<<<<<<<<<<<<

We need to add a second stream to avoid the possibility of the ! jumping over the stream and creating a loop.

Now we want to mix this with the standard Quine format. Since Lost is based very much on Klein I've basically stolen borrowed the Klien Quine for Martin Ender.

:2+@>%?!< "
<<<<^<<<<<<
<<<<^<<<<<<

This quite conveniently prints the first line of the quine. Now all we need to do is hard-code the streams. Well this is easier said than done. I tried approximately four different methods of doing this. I'll just describe the one that worked.

The idea here is to use doors to get the desired number of arrows. A Door is a special type of mirror that changes every time it is hit. [ reflects ips coming from the left and ] from the right. When they are hit by an ip from either of these sides the switch orientation. We can make a line of these doors and a static reflector to repeatedly perform an operation.

>:[[[

Will perform : three times. This way if we push a < to the stack before hand we can make a lot of them with less bytes. We make 2 of these, one for each line, and in between them we lay down a newline, however the second one needs only go until it covers the ! we added it for, anything else can be left empty saving us a few bytes. Ok now we need to add the vertical arrows to our streams. This is where the key optimization comes in. Instead of redirecting all the ips to the "start" of the program directly we will instead redirect them to the far left, because we already know that the ips starting in far left must work (or at least will work in the final version) we can also just redirect the other ips. This not only makes it cheaper in bytes, I think this optimization is what makes the quine possible.

However there are still some problems, the most important one being ips starting after the > has been pushed but before we start making copies of it. Such ips will enter the copier and make a bunch of copies of 0. This is bad because our stack clearing mechanism uses zeros to determine the bottom of the stack, leaving a whole bunch of zeros at the bottom. We need to add a stronger stack sanitation method. Since there is no real way of telling if the stack is empty, we will simply have to attempt to destroy as many items on the stack as possible. Here we will once again use the door method described earlier. We will add ((((((((((([[[[[[[[[[[[[[ to the end of the first line right after the sanitizor to get rid of the zeros.

Now there is one more problem, since we redirected our streams to the upper left ips starting at the % and moving down will already have turned the safety off and will exit prematurely. So we need to turn the safety off. We do this by adding a # to the stream, that way ips flowing through the stream will be turned off but ips that have already been sanitized will not. The # must also be hard coded into the first line as well.

That's it, hopefully you understand how this works now.

Wheat Wizard

Posted 2011-01-28T00:34:05.293

Reputation: 33 549

:/ so many typos and missing links – ASCII-only – 2017-08-22T07:28:36.653

16

GolfScript, 8 bytes

I always thought the shortest (true) GolfScript quine was 9 bytes:

{'.~'}.~

Where the trailing linefeed is necessary because GolfScript prints a trailing linefeed by default.

But I just found an 8-byte quine, which works exactly around that linefeed restriction:

":n`":n`

Try it online!

So the catch is that GolfScript doesn't print a trailing linefeed, but it prints the contents of n at the end of the program. It's just that n contains a linefeed to begin with. So the idea is to replace that with the string ":n`", and then stringifying it, such that the copy on the stack prints with quotes and copy stored in n prints without.

As pointed out by Thomas Kwa, the 7-byte CJam quine can also be adapted to an 8-byte solution:

".p"
.p

Again, we need the trailing linefeed.

Martin Ender

Posted 2011-01-28T00:34:05.293

Reputation: 162 549

5Golfscript is weird. – CalculatorFeline – 2016-03-23T04:27:50.910

15

Yup, 1165 879 606 561 540 522 498 + 7 = 505 bytes

Requires the -cheat flag to allow the definition of aliases.

022222120211111102222122021121202222212021112202222110222212202112110222221202122212022222102222212021222120222221022222102222210222221202222110222211022222210222221022222210222212202222221022221102211110222221022221220222212202112120221111022212202211210222212022222102211120222122022111202222120212212021221202222221022111102221210222122022222102222120212212022221102211110222122022221102222120212212022112120221111022212202112120222212=%;0e-=<;0<-=>;:0~--=1;1>=2;0%{{>0<~{~>~<<}>>>]}>]}${<#}%{@}

Try it online!

Explanation

There are two parts to this (as with most quines). The data:

022222120211111102222122021121202222212021112202222110222212202112110222221202122212022222102222212021222120222221022222102222210222221202222110222211022222210222221022222210222212202222221022221102211110222221022221220222212202112120221111022212202211210222212022222102211120222122022111202222120212212021221202222221022111102221210222122022222102222120212212022221102211110222122022221102222120212212022112120221111022212202112120222212

And the decoder:

=%;0e-=<;0<-=>;:0~--=1;1>=2;0%{{>0<~{~>~<<}>>>]}>]}${<#}%{@}

The data is merely a binary encoding of the decoder (or rather its reverse). Each 0 starts a new character and the 1s and 2s are the 0- and 1-bits, respectively.

Note that 0 is a standard Yup command which pushes a zero, while 1 and 2 are not defined at this point. However, we assign the entire data part to the command % so that the 1 and 2 can remain undefined until % is actually used.

Next, we define some more commands:

0e-=<;
0<-=>;
:0~--=1;
1>=2;

< decrements the top of the stack, > increments it. 1 (somewhat unintuitively) doubles the top of the stack. 2 doubles it and then increments it. Thanks to these definitions, something like 0221111 will actually leave a 48 (110000 in binary) on the stack.

The remaining 32 bytes do the actual decoding in two parts. First we need to reconstruct the data string.

0%                ` Push a zero and then the data.
{                 ` For each value...
  {               `   Until that value is zero...
    >0<~{~>~<<}>  `   divmod 2. The div is the input to the next iteration,
                  `   the mod gives us the next bit.
    >>]           `   Increment twice (gives 2 or 3) and put at the bottom
                  `   of the stack.
  }
  >]              ` Increment the 0 and put it at the bottom as well.
}
$                 ` Reverse the entire stack.
{<#}              ` Decrement and print each number.

And finally, we push the data again and print each value as a character:

%{@}

For future reference, here is a CJam script to encode the data.

Martin Ender

Posted 2011-01-28T00:34:05.293

Reputation: 162 549

14

Fob (135)

If Fob, a language of my own creation some time ago, I present a rather interesting 135 byte quine:

$$#<&$::#<&$:#<&#<&$:#<=#<&$&//%<//<.&%<<%.%<&>/////%<<%.<&.%<.%/////<&.%<<&/.%%<&>%</%<////<&.%<<%/<&.%%<&>/%//<&.%<</&.%%%<&>>/>>#<=

Hiato

Posted 2011-01-28T00:34:05.293

Reputation: 711

"If Fob, a lan" – CalculatorFeline – 2017-05-25T01:17:29.810

14

Perl, 30 28 chars

printf+(q(printf+(q(%s))x2))x2

I first posted this one years ago to the Fun With Perl mailing list, and I've been quite fond of it ever since.

You can save two characters if you use qw instead of q:

printf+qw(printf+qw(%s)x2)x2

Ilmari Karonen

Posted 2011-01-28T00:34:05.293

Reputation: 17 947

3This is the shortest Perl quine I'm aware of (which doesn't read $0, that is). – primo – 2013-06-20T12:43:16.543

14

Jelly, 3 bytes

”ṘṘ

Try it online!

Verification

$ echo $LANG
en_US
$ xxd -g 1 quine.jelly
0000000: ff cc cc                                         ...
$ ./jelly f quine.jelly | xxd -g 1
0000000: ff cc cc                                         ...

How it works

”ṘṘ    Main link. No input.

”Ṙ     Set the return value to the character 'Ṙ'.
  Ṙ    Print a string representation of the return value.
       This prints: ”Ṙ
       (implicit) Print the return value.
       This prints: Ṙ

Dennis

Posted 2011-01-28T00:34:05.293

Reputation: 171 923

Which version of the interpreter does this use? When I test it, it outputs in UTF-8 even though the input is in Jelly's codepage (and the change in encoding would make it not-a-quine). – None – 2016-12-07T13:37:06.863

1

The output's encoding depends on your terminal's settings: if it's set to UTF-x, it uses that; if it's set to anything else, it uses Jelly's code page. On Linux, LANG=en_US achieves just that. https://tio.run/nexus/bash#@@/j6Odum5oXHxrMVVGRoqBbpKBbUKxgY2OjkJaWDAQKdgqFpZl5qXpZqTk5lRA16QqGKIL6@QUl@mAmhFRIQ5ZWqFGA6fr/HwA

– Dennis – 2016-12-07T16:06:16.560

12

><> (Fish) - 8 chars

Prints itself but throws an error

"r0:g>o<

13 For no error (old Fish)

"r0:g!;>?o?|;

15 if you think g is cheating

"r1b3*+!;>?o?|;

cthom06

Posted 2011-01-28T00:34:05.293

Reputation: 633

In old fish the ? command did not pop the stack, new fish does – JNF – 2015-05-27T18:53:39.607

I would suggest, for new ><>, "r0:g&gt;o_!~l?!;!_|, or "r13b*+&gt;o_!~l?!;!_| for no g version (which I don't view as cheating anyway...). But then you're not better off from "r00g!;oooooooo| (16) – JNF – 2015-05-27T20:57:16.097

Last two ones don't work for me. They output rg&gt;? and r3!?|, respectively. They seem to skip two characters every time... – tomsmeding – 2013-04-22T05:55:01.833

@tomsmeding I think the interpreter changed some point after this answer, hence the (old fish) in parentheses. Though I honestly can't remember it was 2 years ago. I know they worked when i posted my answer. – cthom06 – 2013-04-22T13:19:16.340

1I've been looking at this for a little bit (longer than I should have!) and I've come up with this quine which errors but doesn't use g; #o<}-1:" respectively; #.09;!?lo}-1:" for the non error one. being 8 bytes and 14 bytes. – Teal pelican – 2016-12-19T14:33:17.830

@Tealpelican brilliant! I never even thought about ' # ' - 1 being ' " ' – cthom06 – 2016-12-20T19:54:56.880

12

Haskell (50 characters)

main=putStr$q++show q;q="main=putStr$q++show q;q="

AardvarkSoup

Posted 2011-01-28T00:34:05.293

Reputation: 324

11

dc - 16 characters

[91PP6120568P]dx

Geoff Reedy

Posted 2011-01-28T00:34:05.293

Reputation: 2 678

6There's this for 10: 6581840dnP – Digital Trauma – 2015-02-26T22:22:01.590

1I knew you could print a character based on an ASCII code directly or a number % 256, but not a string using the coefficients of a base 256 polynomial as individual characters. Awesome! – seshoumara – 2016-09-07T10:05:35.093

Same length: [91PP93P[dx]p]dx (taken from Reddit)

– mbomb007 – 2016-10-26T14:53:23.513

11

Triangular, 18337

...................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................,94942339352462393733242422402282678746947594827594678246942219941994753536322424463225469422223987242539322425469475943836248282228238392446947594383433242467274646946730621520949494282828<>HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH33pp)95*P973**(:(dUi@p]pd]pUd@p(%p%p]562**@2+@p((9i*+92*+@p]p86*dd(d89*@p]p843**U-@@pU0P!&ppp...HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH``

Since this contains un-printables here's a pastebin. Try it online!

Explanation

Here is the relevant portion of the code with a line breaks where they would be inserted:

  ,94942339352462393733242422402282678746947594827594678246942219941994753536322424463225469422223987242539322425469475943836248282228238392446947594383433242467274646946730621520949494282828<
 >HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH33pp)95*P973**(:(dUi@p]pd]pUd@p(%p%p]562**@2+@p((9i*+92*+@p]p86*dd(d89*@p]p843**U-@@pU0P!&ppp...HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH`
`

The Hs are there because they are easier to print than ., but they have the same function, so I'll replace them and all the other noops with .:

  ,94942339352462393733242422402282678746947594827594678246942219941994753536322424463225469422223987242539322425469475943836248282228238392446947594383433242467274646946730621520949494282828<
 >................................................33pp)95*P973**(:(dUi@p]pd]pUd@p(%p%p]562**@2+@p((9i*+92*+@p]p86*dd(d89*@p]p843**U-@@pU0P!&ppp.................................................`
`

Like most quines this comes in two parts, an encoder and a decoder. The encoder is the line full of numbers and the decoder is the line full of symbols. Each pair of numbers in the encoder represents a single character in the decoder. Once we have encoded we get pushed down to the decoder.

The first thing in the encoder (besides 33pp which is just there for spacing) is ). This tells triangular to jump back to the start of the most recent loop. However since we have not opened a loop there is nothing to go back to so it does nothing. This will be used later to yoyo the ip when we don't want it to run the decoder.

We then store - to the register with 95*P, this will be used to create both , and .. We then push 189 which is the number of blank lines before the code starts. We use this and a loop to generate all the empty lines before the code starts.

(:(dUi@p]pd]

Once our loop is done we add the , with pUd@p. Now we are ready to decode the encoder, this is done with the simple loop:

(%p%p]

Each %p prints one of the numbers off the top of the stack. We have two of them because some of the numbers have zero as their second digit, meaning in order to get the loop to go through all the encoder we need to print them two at a time.

Once the encoder has been printed we print <> which makes up the two redirects that are needed.

562**@2+@p

Now we need to fetch another copy of the encoder. To start we open a loop with ( this will be closed by the ) we encountered earlier allowing us to spring back to where we were first.

But first we have to run through the decoding section once. The decoding section combines the two numbers as a double digit number in base 10 and adds 18 to the result, since our stack is currently empty this will decode to 18 directly. Thats what accounts for the unprintable in the quine. Once we have "decoded" a character we run through the bit of the program that creates the padding, we make half the padding and leave the other half to be made later. Next up we is the code that makes the backticks. Since we absolutely cannot have any of these just lying around we subtract the register from the result to makes some significantly less harmful 3s. Lastly we use the check the contents of the register, exiting on zero. Since we don't have anything we continue on for later. In order to make sure the next run does terminate we put a 0 in the register.

The ip runs through the encoder again and gets yoyo'd back to our decoder again.

Now we are ready to decode everything. The first loop

(9i*+92*+@p]p

Converts to base 10 adds 18 and outputs, it does this until we have emptied the stack.

Next up we create the padding. We already created half the padding the first run through so we only have half left.

86*dd(d89*@p]p

Once again we pad with H because its cheaper to make than . in this situation.

Now we make the backticks. We make them using 843** and subtract the contents of the register using U-, since we previously set the register to zero we output backtick this time.

Now we exit by checking the contents of the register:

U0P!&

(there are also 3 ps at the end of the code, I don't know why they need to be there but they do, a bunch of weird characters end up in the output otherwise)

Wheat Wizard

Posted 2011-01-28T00:34:05.293

Reputation: 33 549

11

Python 3, 54

I have never seen this one before, so here's my fair creation. It is longer than the classical one but it is a single expression.

print(str.format(*['print(str.format(*[{!r}]*2))']*2))

Evpok

Posted 2011-01-28T00:34:05.293

Reputation: 548

@flornquake Then wouldn't it be four bytes shorter, because of the print(...) within the string? – HyperNeutrino – 2016-02-11T23:59:12.553

1@Alex No, because you need to add a space after each print. – flornquake – 2016-02-20T23:04:07.843

@flornquake Right. Thanks. Also, nice username. It's interesting. – HyperNeutrino – 2016-02-21T02:44:29.590

3btw, this is 2 bytes shorter in Python 2, where you don't need the parentheses after print. – flornquake – 2014-09-15T09:40:19.627

10

Threead, 85 bytes

>93>60>111>99>91>60>93>62>111>100>111>99>50>54>105>91>62>93>60>91[<]>[i62codo>]<[co<]

Try it online!

>93>60>...60>91      # Encodes the second part backwards
[<]>                 # Go back to the begining
    [        ]       # for every number
     i               # insert an extra cell
      62co           # print a '>' 
          d          # delete the cell
           o         # print the original number in this cell
            >        # go to the next cell
              <[  <] # for every cell in reverse order
                co   # print the character that it represents

Riley

Posted 2011-01-28T00:34:05.293

Reputation: 10 445

That's really cool. Explanation to come? – Pavel – 2017-01-13T00:28:12.937

@Pavel Working on it now :) – Riley – 2017-01-13T00:28:39.430

That's, actually much more simple than the solution I had planned. – ATaco – 2017-01-13T00:33:55.597

10

A Classic - Lisp - 78

((lambda (x) (list x (list 'quote x))) '(lambda (x) (list x (list 'quote x))))

A beautiful snippet, but give credit where credit is due.

arrdem

Posted 2011-01-28T00:34:05.293

Reputation: 730

7Actually this code returns itself instead of printing itself. Running it in an interpreter with read-eval-print loop will of course print the returned list, but the printing is not part of the code itself. The C equivalent of this would be a C code which outputs its executable instead of its source code. Which would certainly also be a quite interesting problem, although heavily system-dependent. – celtschk – 2012-02-03T16:13:41.650

that would make it not different from one of those function quines – Destructible Lemon – 2017-06-24T08:52:37.490

the link is dead – Def – 2018-01-15T21:02:36.297

10

JavaScript, 31 characters

function f(){alert(f+"f()")}f()

Is this seriously the shortest JavaScript quine here?

Kendall Frey

Posted 2011-01-28T00:34:05.293

Reputation: 2 099

75, without recursion: !function (x){alert('!'+x+'('+x+')')}(function (x){alert('!'+x+'('+x+')')}) – sdleihssirhc – 2014-10-27T05:12:08.103

9

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

Posted 2011-01-28T00:34:05.293

Reputation:

http://codegolf.stackexchange.com/a/55943/42545 I should've implemented it sooner ;-) – ETHproductions – 2016-12-04T04:32:32.530

Not really a big deal to have two languages with the same name. It's happened before.

– None – 2016-12-04T04:34:34.193

You can only claim byte counts that are supported by an implementation. Unless 7 is implemented on a system that stores raw bits, the byte count for this answer should be 2. – Dennis – 2016-12-06T19:13:39.607

@Dennis: The language's implementation ignores any 1 bits at the end of the program, throwing them away as it reads them; they're just padding to allow the language to be stored on a disk (in much the same way as some older computer systems couldn't read files in units smaller than, say, 80 bytes). Do you consider that to count? – None – 2016-12-06T19:48:09.730

Whether the bits are ignored by the interpreter are irrelevant; what counts is the size of the source code. Unless you can actually save your source code using only 15 bits, the byte count is 2. – Dennis – 2016-12-06T19:51:20.687

I'll mark it as 2 bytes for the time being, then, but this probably deserves a meta post of its own for discussion. – None – 2016-12-06T19:55:23.920

I love it. 7th upvote btw ;) – FatalMerlin – 2017-04-26T11:46:33.030

9

Forte, 66 bytes

Updated for the new Interpreter

2PUT34:LET1=3
4PUT34:END
1PRINT
"2PUT34:LET1=3
4PUT34:END
1PRINT
"

Which, in order is:

1: Print the first half of the code.
2: Print a ", then set line 3 to be line 1.
3: Print the second half of the code again.
4: Print another ", then end the program.

Try it online!

ATaco

Posted 2011-01-28T00:34:05.293

Reputation: 6 373

I remember when you and me were trying to do this. I am still impressed – Christopher – 2017-04-02T22:07:50.027

Why the bounty? – MD XF – 2017-05-24T23:38:31.613

@MDXF Bounty was for writing a Forte quine, which at the time, hadn't been done. – ATaco – 2017-05-24T23:50:41.277

@ATaco Ah, got it. Cheers – MD XF – 2017-05-24T23:51:22.997

9

Java 6 - 138 110 106

Since the question says "golf you a quine", I took Steve P's quine and golfed it:

enum Q{X;{String s="enum Q{X;{String s=%c%s%1$c;System.out.printf(s,34,s);}}";System.out.printf(s,34,s);}}

With credits to Trixie Wolf and Volune.
Note: you need to ignore stderr (e.g. 2>/dev/null)

For great good (and justice)!

aditsu

Posted 2011-01-28T00:34:05.293

Reputation: 20 689

I can't get this to work. Did you actually try to compile it? I think you need a System.exit() gimmick or it will fail to run properly. I'll add an answer here with my implementation later if I don't hear back from you soon. – Trixie Wolf – 2014-08-16T04:00:10.033

Actually: given the "ignore stderr" comment obv. you did get it to work. I'm very curious how, though. – Trixie Wolf – 2014-08-16T04:19:28.330

@TrixieWolf It works fine here, there is absolutely no compile error. Did you think I would post it without trying it first? :p Anyway, you can only run it with java 6 (or 5), newer versions check for the main method first. – aditsu – 2014-08-16T07:52:40.037

I'd like to suggest this improvement: enum Q{X;{String s="enum Q{X;{String s=%c%s%1$c;System.out.printf(s,34,s);}}";System.out.printf(s,34,s);}} – Volune – 2014-08-17T11:47:21.840

@aditsu Ah, that makes perfect sense. I'm busy today, but tomorrow I will check to see if mine still functions correctly (I tested it recently but I'll bet it was on J6). It might still work due to the exit() trick. – Trixie Wolf – 2014-08-17T21:35:33.183

@Volune That's my quine, Volune. :) Well, the one I've been asking about anyway (I am not the original source; found it years ago and adapted it). – Trixie Wolf – 2014-08-17T21:36:13.163

9

Ceylon 1647 1165 885 739 672 566 388 187 178 bytes

Late, and won't win anything ... but I'm trying out how Ceylon works.

An one-liner now:

shared void e(){value q="\"\"\"";value t="""shared void e(){value q="\"\"\"";value t=""";value b=""";print(t+q+t+q+";value b="+q+b+q+b);}""";print(t+q+t+q+";value b="+q+b+q+b);}`

The ungolfed original (1647 bytes):

shared void quine69() {
    void printQuoted(String line) => print("        \"" + line + "\"");
    void printQuotedWithComma(String* seq) {
        for (line in seq) {
            print("        \"" + line.replace("\\", "\\\\").replace("\"".string, "\\\"") + "\",");
        }
    }
    void printLines(String* seq) {
        for (line in seq) {
            print(line);
        }
    }
    value top = [
        "shared void quine69() {",
        "    void printQuoted(String line) => print(\"        \\\"\" + line + \"\\\"\");",
        "    void printQuotedWithComma(String* seq) {",
        "        for (line in seq) {",
        "            print(\"        \\\"\" + line.replace(\"\\\\\", \"\\\\\\\\\").replace(\"\\\"\".string, \"\\\\\\\"\") + \"\\\",\");",
        "        }",
        "    }",
        "    void printLines(String* seq) {",
        "        for (line in seq) {",
        "            print(line);",
        "        }",
        "    }",
        "    value top = ["
    ];
    value bottom = [
        "    ];",
        "    printLines(*top);",
        "    printQuotedWithComma(*top.exceptLast);",
        "    printQuoted(top.last);",
        "    print(\"    ];\");",
        "    print(\"    value bottom = [\");",
        "    printQuotedWithComma(*bottom.exceptLast);",
        "    printQuoted(bottom.last);",
        "    printLines(*bottom);",
        "}"
    ];
    printLines(*top);
    printQuotedWithComma(*top.exceptLast);
    printQuoted(top.last);
    print("    ];");
    print("    value bottom = [");
    printQuotedWithComma(*bottom.exceptLast);
    printQuoted(bottom.last);
    printLines(*bottom);
}

The second try, mainly with shorter names, and extract the quote function (to 1165 bytes):

shared void q() {
    String q1(String l) => "        \"" + l.replace("\\", "\\\\").replace("\"".string, "\\\"") + "\"";
    void pQ(String l) => print(q1(l));
    void pQC(String* seq) { for (l in seq) { print(q1(l) + ","); } }
    void pL(String* seq) { for (l in seq) { print(l); } }
    value t = [
        "shared void q() {",
        "    String q1(String l) => \"        \\\"\" + l.replace(\"\\\\\", \"\\\\\\\\\").replace(\"\\\"\".string, \"\\\\\\\"\") + \"\\\"\";",
        "    void pQ(String l) => print(q1(l));",
        "    void pQC(String* seq) { for (l in seq) { print(q1(l) + \",\"); } }",
        "    void pL(String* seq) { for (l in seq) { print(l); } }",
        "    value t = ["
    ];
    value b = [
        "    ];",
        "    pL(*t);",
        "    pQC(*t.exceptLast);",
        "    pQ(t.last);",
        "    print(\"    ];\");",
        "    print(\"    value b = [\");",
        "    pQC(*b.exceptLast);",
        "    pQ(b.last);",
        "    pL(*b);",
        "}"
    ];
    pL(*t);
    pQC(*t.exceptLast);
    pQ(t.last);
    print("    ];");
    print("    value b = [");
    pQC(*b.exceptLast);
    pQ(b.last);
    pL(*b);
}

The third try omits the indentation (I had to change my IDE settings to turn auto-formatting off). This gets us to 885 bytes:

shared void i() {
String q1(String l) => "\"" + l.replace("\\", "\\\\").replace("\"".string, "\\\"") + "\"";
void pQ(String l) => print(q1(l));
void pQC(String* seq) { for (l in seq) { print(q1(l) + ","); } }
void pL(String* seq) { for (l in seq) { print(l); } }
value t = [
"shared void i() {",
"String q1(String l) => \"\\\"\" + l.replace(\"\\\\\", \"\\\\\\\\\").replace(\"\\\"\".string, \"\\\\\\\"\") + \"\\\"\";",
"void pQ(String l) => print(q1(l));",
"void pQC(String* seq) { for (l in seq) { print(q1(l) + \",\"); } }",
"void pL(String* seq) { for (l in seq) { print(l); } }",
"value t = ["
];
value b = [
"];",
"pL(*t);",
"pQC(*t.exceptLast);",
"pQ(t.last);",
"print(\"];\");",
"print(\"value b = [\");",
"pQC(*b.exceptLast);",
"pQ(b.last);",
"pL(*b);",
"}"
];
pL(*t);
pQC(*t.exceptLast);
pQ(t.last);
print("];");
print("value b = [");
pQC(*b.exceptLast);
pQ(b.last);
pL(*b);
}

The fourth version has also the internal spaces, and some line breaks removed, comes down to 739 bytes:

shared void n(){
String q1(String l)=>"\""+l.replace("\\","\\\\").replace("\"","\\\"")+"\"";
void pQ(String l)=>print(q1(l));
void pQC(String*s){for(l in s){print(q1(l)+",");}}
void pL(String*s){for(l in s){print(l);}}
value t=[
"shared void n(){",
"String q1(String l)=>\"\\\"\"+l.replace(\"\\\\\",\"\\\\\\\\\").replace(\"\\\"\",\"\\\\\\\"\")+\"\\\"\";",
"void pQ(String l)=>print(q1(l));",
"void pQC(String*s){for(l in s){print(q1(l)+\",\");}}",
"void pL(String*s){for(l in s){print(l);}}",
"value t=["
];value b=[
"];",
"pL(*t);pQC(*t.exceptLast);pQ(t.last);",
"print(\"];value b=[\");",
"pQC(*b.exceptLast);pQ(b.last);pL(*b);",
"}"
];
pL(*t);pQC(*t.exceptLast);pQ(t.last);
print("];value b=[");
pQC(*b.exceptLast);pQ(b.last);pL(*b);
}

For the next version I tried a different approach, to avoid all this escaping. Ceylon has (like Python) a "long string literal" format – everything between """ and """ is part of a string, with no escapes. ... But the indentation is removed, and because the """ itself is already 3 chars long, we also need at least those the spaces of indentation. For printing this string literal we also need to add those indentation back, and we need to handle the first and last line specially (the first needs to have """ in front, the last one is better omitted, otherwise we get one line more in the output than we already had. This (and replacing some identifiers by one-letter ones) gets us down to 672 bytes:

shared void e(){
value _="   ";value q="\"\"\"";
void r(String? l)=>print(q+(l else""));
void s(String l)=>print(_+q+l);
void c(String*s){for(l in s){print(_+l);}}
value t=

"""shared void e(){
   value _="   ";value q="\"\"\"";
   void r(String? l)=>print(q+(l else""));
   void s(String l)=>print(_+q+l);
   void c(String*s){for(l in s){print(_+l);}}
   value t=
   """;value b=
"""print(t);r(t.lines.first);c(*t.lines.rest.exceptLast);
   s(";value b=");
   r(b.lines.first);c(*b.lines.rest.exceptLast);s(";");print(b);
   }
   """;
print(t);r(t.lines.first);c(*t.lines.rest.exceptLast);
s(";value b=");
r(b.lines.first);c(*b.lines.rest.exceptLast);s(";");print(b);
}

(This has an empty trailing line, which Stack Exchange doesn't show. Same for the next ones.)

By inlining the two short functions r and s (their savings are less than the function definition), and extracting the long .lines.rest.exceptLast expression into the c function, we get down to 566 bytes:

shared void e(){
value _="   ";value q="\"\"\"";
void c(String s){for(l in s.lines.rest.exceptLast){print(_+l);}}
value t=

"""shared void e(){
   value _="   ";value q="\"\"\"";
   void c(String s){for(l in s.lines.rest.exceptLast){print(_+l);}}
   value t=
   """;value b=
"""print(t);print(q+(t.lines.first else""));c(t);
   print(_+q+";value b=");
   print(q+(b.lines.first else""));c(b);print(_+q+";");print(b);
   }
   """;
print(t);print(q+(t.lines.first else""));c(t);
print(_+q+";value b=");
print(q+(b.lines.first else""));c(b);print(_+q+";");print(b);
}

Another, now "obvious" optimization would be to remove the line breaks (and most of the indentation) inside our long string literals here. By that, we actually only the first and last line of each to handle (first is to be printed with """, and the empty last one we print manually with the stuff behind it), and can get rid of the long c function which looped over everything but first and last line. This gets us down to 388:

shared void e(){value _="   ";value q="\"\"\"";value t=

"""shared void e(){value _="   ";value q="\"\"\"";value t=
   """;value b=
"""print(t);print(q+(t.lines.first else""));print(_+q+";value b=");print(q+(b.lines.first else""));print(_+q+";");print(b);}
   """;
print(t);print(q+(t.lines.first else""));print(_+q+";value b=");print(q+(b.lines.first else""));print(_+q+";");print(b);}

Now we can ask: why do we have many print statements, instead of using just one and some string concatenation? This gets rid of the remaining line breaks (and also the trailing empty line), and gets us down to 185 bytes (including the new line character at the end):

shared void e(){value q="\"\"\"";value t="""shared void e(){value q="\"\"\"";value t=""";value b="""print(t+q+t+q+";value b="+q+b+q+";"+b);}""";print(t+q+t+q+";value b="+q+b+q+";"+b);}

Here slightly easier to read (but without syntax highlighting):

shared void e(){value q="\"\"\"";value t="""shared void e(){value q="\"\"\"";value t=""";value b="""print(t+q+t+q+";value b="+q+b+q+";"+b);}""";print(t+q+t+q+";value b="+q+b+q+";"+b);}

We can actually remove another 9 characters by putting this single ; inside the b string:

shared void e(){value q="\"\"\"";value t="""shared void e(){value q="\"\"\"";value t=""";value b=""";print(t+q+t+q+";value b="+q+b+q+b);}""";print(t+q+t+q+";value b="+q+b+q+b);}

I don't see how this could be shrunk further anymore ... maybe with a totally different approach.

(I did put a commented version of this into my new Github repository).

As a bonus, an "ungolfed version" of the last one (463 chars):

shared void quine(){
    value quote = "\"\"\"";
    value top = """shared void quine(){#    value quote = "\"\"\"";#    value top = """;
    value bottom = """    print(top.replace("#","\n") + quote + top + quote + ";\n    value bottom = " + quote + bottom + quote + ";\n" + bottom.replace("$"+"$","\n"));$$}""";
    print(top.replace("#","\n") + quote + top + quote + ";\n    value bottom = " + quote + bottom + quote + ";\n" + bottom.replace("$"+"$","\n"));
}

This needed some additional tricks to encode the line breaks in each of the string literals, because once they should be printed directly, once not. In top, I use # as a replacement. In bottom, where I replace the # in top by a newline, we need to use a different replacement string. I chose the two letter-string $$, because that can be escaped by string concatenation.

Paŭlo Ebermann

Posted 2011-01-28T00:34:05.293

Reputation: 870

Dang! This is crazy! +1 – refi64 – 2015-09-14T21:13:01.330

8

Mini-Flak, 6900 bytes

Mini-flak is a Turing complete subset of Brain-Flak. It works exactly like Brain-Flak except the [], <> and <...> operations are banned from use. Programming in Min-Flak is thus much more difficult than traditional Brain-Flak.

The main difficulty with Mini-Flak is the lack of random access. While Mini-flak is Turing complete, location of access (relative to the top of the stack) must be determined at compile time rather than run time.


The following is the quine. Unfortunately this quine has an order notation of O(7**n) (where n is its own length) and thus cannot be run to completion in the lifetime of the universe. I will hopefully convince you that it does work but for now you will have to trust me a bit. If you want a version that can be run in the lifetime of the universe (or an afternoon) you can scroll down a bit to my faster version.

(())(())(()()()()())(()()()()()())(())(()()()()())(()()()()()())(()())(()())(()()())(())(()()()()())(()()()()()())(()()())(()()()()())(()()()()()())(()()()())(()())(()()()())(()())(()()()()())(())(())(())(())(())(())(())(()()()()())(()()()()()())(())(()()()()())(()()()()()())(()())(()())(()()())(())(()()()()())(()()()()()())(()()())(()()()()())(()()()()()())(()()()())(()())(()()()())(()())(()())(()()()()())(()()()()()())(()())(()())(()()()()())(()()()()()())(()()()()())(()()()()()())(()()()()())(()()()()()())(()()()()())(()()()()()())(())(()()()()())(()()()()()())(()())(()())(()()())(())(()()()()())(()()()()()())(()()())(()()()()())(()()()()()())(()()()())(()())(()()()())(()())(()()()()()())(()()()()())(()()()()()())(())(())(()()()()())(()()()()()())(()())(()()())(())(()()()()())(())(())(()()()()())(()()()()()())(()()())(())(())(())(())(()())(())(()())(())(()())(()())(()()()()())(()()()()()())(())(()())(()())(()())(()()()())(()()()()())(()()()()()())(()())(())(()()())(())(())(())(()()()()())(()()()()()())(())(()()()()())(()()()()()())(()())(()())(()()())(())(()()()()())(()()()()()())(()()())(()()()()())(()()()()()())(()()()())(()())(()()()())(()())(()())(()()()())(()()()()())(()()()()()())(()())(()())(()()()()())(())(()()()()())(()()()()()())(()()())(())(()())(())(())(())(()()()()())(()()()()()())(())(()())(()()())(())(()()()()())(()()()()()())(()())(()()()())(()())(()())(()()()()())(()()()()())(()()()()()())(())(()()())(())(())(()()()()())(()()()()()())(())(()()()()())(()()()()()())(()()())(())(())(()()()()())(()()()()()())(()()())(())(()())(()()()())(()())(()())(()()()())(()()()()())(()()()()()())(()())(()())(()())(()()()())(()()()()())(()()()()()())(()())(()()()()()())(()()()()())(()()()()()())(()())(()()()())(()()()()())(()()()()()())(()())(()()()()()())(())(())(()()()()())(()()()()()())(()()()()())(()()()()()())(()()())(())(()()()()())(()()()()()())(()())(()()()())(()()()()())(()()()()()())(())(()()()()())(()()()()()())(()())(()())(()()())(())(()()()()())(()()()()()())(()()())(()()()()())(()()()()()())(()()()())(()())(())(())(()()()()())(()()()()()())(()()())(())(()())(())(())(())(())(())(())(()())(())(()())(())(()())(())(()())(())(()())(()())(()()()()())(()()()()()())(()())(()()()()())(()()()()()())(()())(()()()()())(()()()()()())(()())(()())(()()()())(()()()()())(()()()()()())(()())(()()()()())(())(()()())(())(())(()()()()())(()()()()()())(()()())(())(()())(())(())(()()()()())(()()()()()())(())(()())(()())(()())(()()()())(()()()()())(()()()()()())(()())(()()()()())(())(()()())(())(())(()()()()())(()()()()()())(()()())(())(()())(())(())(())(()()()()())(()()()()()())(()())(()()()()())(()()()()()())(())(())(())(()())(())(()())(())(()())(()())(()())(()()()()())(()()()()()())(()()()()())(()()()()()())(()())(()())(()()()())(()()()()())(()()()()()())(()())(()()()()())(())(()()())(())(())(()()()()())(()()()()()())(()()())(())(()())(())(())(()()()()())(()()()()()())(())(()())(())(()())(()())(()())(()()()())(()()()()())(()()()()()())(()())(()()()()())(())(()()())(())(())(()()()()())(()()()()()())(()()())(())(()())(())(())(()()()()())(()()()()()())(())(())(())(())(()())(())(()())(())(()())(())(()())(())(()())(()())(()())(()()()()())(()()()()()())(()()()()())(()()()()()())(()())(()()()()())(()()()()()())(()())(()())(()()()())(()()()()())(()()()()()())(()())(()()()()())(())(()()())(())(()()()()())(()()()()()())(())(()()()()())(()()()()()())(())(()())(())(()())(()())(()())(()()()())(()()()()())(()()()()()())(()())(()()()()()())(()()()()())(()()()()()())(()())(()()()())(()()()()())(()()()()()())(()())(()()()()()())(()()()()())(()()()()()())(()())(()()()())(()()()()())(()()()()()())(()())(()()()()()())(()()()()())(()()()()()())(()())(()()()())(()()()()())(()()()()()())(()())(()()()()()())(()()()()())(()()()()()())(()())(()()()())(()()()()())(()()()()()())(()())(()()()()()())(()()()()())(()()()()()())(()())(()()()())(()()()()())(()()()()()())(()())(()()()()()())(()()()()())(()()()()()())(()())(()()()())(()()()()())(()()()()()())(()())(()()()()())(())(())(()()()()())(()()()()()())(()()())(())(())(())(())(()())(())(()())(())(()())(()())(()()()()())(()()()()()())(())(()())(()())(()())(()()()())(()()()()())(()()()()()())(()())(())(()()())(())(())(())(()()()()())(()()()()()())(())(()()()()())(()()()()()())(()())(()())(()()())(())(()()()()())(()()()()()())(()()())(()()()()())(()()()()()())(()()()())(()())(()()()())(()())(()())(()()()())(()()()()())(()()()()()())(()())(()())(()()()()())(())(()()()()())(()()()()()())(()()())(())(()())(())(())(())(()()()()())(()()()()()())(())(()())(()()())(())(()()()()())(()()()()()())(()())(()()()())(()())(()())(()()()()())(()()()()())(()()()()()())(())(()()())(())(())(()()()()())(()()()()()())(())(()()()()())(()()()()()())(()()())(())(())(()()()()())(()()()()()())(()()())(())(()())(()()()())(()())(()())(()()()())(()()()()())(()()()()()())(()())(()())(()())(()()()())(()()()()())(()()()()()())(()())(()()()()()())(()()()()())(()()()()()())(()())(()()()())(()()()()())(()()()()()())(()())(()()()()()())(())(())(()()()()())(()()()()()())(()()()()())(()()()()()())(()()())(())(()()()()())(()()()()()())(()())(()()()())(()()()()())(()()()()()())(())(()()()()())(()()()()()())(()())(()())(()()())(())(()()()()())(()()()()()())(()()())(()()()()())(()()()()()())(()()()())(()())(())(())(()()()()())(()()()()()())(()()())(())(())(())(())(())(())(()())(())(()())(())(()())(())(()())(())(()())(()())(()()()()())(()()()()()())(()())(()()()()())(()()()()()())(()())(()()()()())(()()()()()())(())(()())(()())(()())(()()()())(()()()()())(()()()()()())(()())(()()()()())(())(()()()()())(()()()()()())(()()())(())(()())(())(())(())(())(())(())(())(()())(())(()())(())(()())(())(()())(())(()())(()())(()()()()())(()()()()()())(()())(()()()()())(()()()()()())(()())(()()()()())(()()()()()())(())(()())(()())(()()())(())(()())(()()()())(()())(()())(()()()())(()()()()())(()()()()()())(()())(()()()()()())(()()()()())(()()()()()())(())(())(())(())(())(()())(())(()())(())(()())(())(()())(())(()())(()())(()()()()())(()()()()()())(()())(()()()()())(()()()()()())(()())(()()()()())(()()()()()())(()())(()())(()()()())(()()()()())(()()()()()())(()())(()()()()()())(()()()()())(()()()()()())(({}({}))[({}[{}])]){((((((({}({}))[({}[{}])])){})){}{}{}{}({}))[({}[{}])])}{}(({})[({(({}[(((()()()){}()))]{})([((({}({}))[({}[{}])]))]{})){({}[()((({}()[({})])){{}([(({}({}[(({}[()]))]{})))]{})}{})]{})}(({}{}[({})]{}({}))[({}[{}])(({}[()(((((()()()()()){}){}){}))]{}){([(({}[()(({}()))]{}){([(({}[()((({}){}((()()())){}{}))]{}){([(({}[()(({}()()))]{}){([(({}[()(({}(((()()()()())){}{}){}))]{}){([({}({}()()))]{})}{})]{})}{})]{})}{})]{})}{})]{})}{})]{})}{})]{}){(({}[(((()()()){}()))]{})([((({}({}))[({}[{}])]))]{})){({}[()((({}()[({})])){{}([(({}({}[(({}[()]))]{})))]{})}{})]{})}(({}{}[({})]{}({}))[({}[{}])(({}[(((((()()()()()){}){}){}()))]{}){({}[()((((((()()()()()){}){}){}())[()]))]{})}{}((((()()()()()){}){}){}))]{})}{}

Explanation

Like my previous Brain-Flak quine This program has two parts. The first part pushes numbers between 1 and 6 to the stack representing the second part of the program using the following key.

1 -> (
2 -> )
3 -> [
4 -> ]
5 -> {
6 -> }

(Since there is no <> in Mini-Flak those characters are left unencoded). It does this in a deterministic fashion so that this section can be reversed by the next section.

The second section is a decoder. It takes the output from the first section and turns it into the code that generates that list and the code represented by that list (this section's source). However this is easier said than done. Because of Mini-Flak's lack of random access we are going to need to abandon Brain-Flak's traditional techniques in favor of some more bizarre methods. This program starts by compressing the entire stack into one base 7 number where each digit is one number in the list. It does that with the following code:

(({}({}))[({}[{}])]){(({}({}))[({}[{}])])((((({})){})){}{}{}{})(({}({}))[({}[{}])])}{}

Try it Online!

This is a pretty straightforward (as far as Mini-Flak goes) program and I won't get into how it works unless any one is interested. (It is a neat little program but to save space I will leave it out).

We now have one single number representing the entire program. I will push a copy to "temporary memory" (the scope) like follows:

(({})[(...)]{})

And decompose the original copy via repeated devision. Each time I remove a digit from the number I will convert it to the code that generates it.

Once I am done with that, the program will put the copy stored in temporary memory back down and begin a second decomposition. This time it will map each digit to the ASCII value of its corresponding brace as it is decomposed from the total.

Once that is done the program has constructed it's source so it simply terminates.


Verification

You might be suspicious of my program. How can we know that it actually works if it won't terminate in the lifetime of the universe?

So I have set up a "toy version" of the original quine to demonstrate that all of the parts are working.

Try it Online!

This version has the first part removed. You can pass the list of numbers that would be generated by the first part as command line arguments. It will construct code that pushes them and the code they represent. I provided a simple test case but I encourage you to try it out with your own! You will notice even with only six characters the run times are starting to become noticeably long. This is because the division I use is O(n). Slow division has always been a reality in Brain-Flak and it carries over into Mini-Flak.

If you have any questions or confusions comment them and I will be happy to address them.


106656 bytes

Now for my fast version.

This version takes about half an hour (175300470 Brain-Flak cycles) to run on my machine using the ruby interpreter. But for the best performance I suggest you use Crain-Flak the C interpreter which is much faster but lacks some of the polish of the ruby interpreter.

Try it online

Explanation

The reason that Miniflak quines are destined to be slow is Miniflak's lack of random access. In the short but slow version (short is a bit of an exaggeration and slow an understatement) I get around this by pushing all the numbers and then packaging them up into one number and unrolling it piece by piece. However this version does it quite differently. I create a block of code that takes in a number and returns a datum. Each datum represents a single character like before and the main code simply queries this block for each one at a time. This essentially works as a block of random access memory.


To construct this block I actually reused a method from my proof that Miniflak is Turing complete. For each datum there is a block of code that looks like this:

(({}[()])[(())]()){(([({}{})]{}))}{}{(([({}{}(%s))]{}))}{}

This subtracts one from the number on top of the stack and if zero pushes %s the datum beneath it. Since each piece decrements the size by one if you start with n on the stack you will get back the nth datum.

This is nice and modular, so it can be written by a program easily.


Next we have to set up the machine that actually translates this memory into the source. This consists of 5 parts as such:

([()]())(()()()())
{({}[(
   -
 )]{})
 1. (({}[()])[((()))]{}){(([({}{})]{}))}{}{([({}{}{}{}
     (((((((((((((((((((((((((((()()()()()){}){}){})((((()()()()){}){}())){}{})(((()()()()){}){}()){})[()()])[((((()()()()()){}){}){}()){}()])((((()()()()()){}){}){}()){}())[((((()()()()()){}){}){}()){}]))[()])())[()])())[()])())[()]))()))[()])((((()()()){}){}()){}){}())[((((()()()){}){}()){}){}])[()])((((()()()()){}){}())){}{})[((((()()()()){}){}())){}{}])
     (()()()())
    )]{})}{}
 2. (({}[()])[((()))]{}){(([({}{})]{}))}{}{([({}{}
     (({}(({}({}))[({}[{}])][(
     ({}[()(
      ([()](((()()[(((((((()()()){})())){}{}){}){})]((((()()()()())){}{}){})([{}]([()()](({})(([{}](()()([()()](((((({}){}){}())){}){}{}))))))))))))
     )]{})
     {({}[()(((({})())[()]))]{})}{}
     (([(((((()()()()){}){}()))){}{}([({})]((({})){}{}))]()()([()()]({}(({})([()]([({}())](({})([({}[()])]()(({})(([()](([({}()())]()({}([()](([((((((()()()())()){}){}){}()){})]({}()(([(((((({})){}){}())){}{})]({}([((((({}())){}){}){}()){}()](([()()])(()()({}(((((({}())())){}{}){}){}([((((({}))){}()){}){}]([((({}[()])){}{}){}]([()()](((((({}())){}{}){}){})(([{}](()()([()()](()()(((((()()()()()){}){}){}()){}()(([((((((()()()())){}){}())){}{})]({}([((((({})()){}){}){}()){}()](([()()])(()()({}(((((({}){}){}())){}){}{}(({})))))))))))))))))))))))))))))))))))))))))))))))
     )]{})[()]))({()([({})]{})}{}()()()())
    )]{})}{}
 3. (({}[()])[((()))]{}){(([({}{})]{}))}{}{([({}{}
      (({}[(
      ({}[()(((((()()()()()){}){}){}))]{}){({}[()(({}()))]{}){({}[()(({}((((()()()){}){}){}()){}))]{}){({}[()(({}()()))]{}){({}[()(({}(((()()()()())){}{}){}))]{}){([(({}{}()))]{})}}}}}{}
      (({}({}))[({}[{}])])
     )]{}({})[()]))
      ({()([({}({}[({})]))]{})}{}()()()()[(({}({})))]{})
    )]{})}{}
 4. (({}[()])[((()))]{}){(([({}{})]{}))}{}{([({}{}(([{}]))(()()()()))]{})}{}
    ({}[()])
}{}

The machine consists of four parts that are run in reverse starting with 4 and ending with 1. I have labeled them in the code above. Each section also uses the same lookup table format I use for the encoding. This is because the entire program is contained in a loop and we don't want to run every section every time we run through the loop so we put in the same RA structure and query the section we desire each time.

4

Section 4 is a simple set up section.

The program tells first queries section 4 and datum 0. Datum 0 does not exist so instead of returning that value it simply decrements the query once for each datum. This is useful because we can use the result to determine the number of data, which will become important in future sections. Section 4 records the number of data by negativizing the result and queries Section 3 and the last datum. The only problem is we cannot query section 3 directly. Since there is another decrement left we need to query a section 4. In fact this will be the case every time we query a section within another section. I will ignore this in my explanation however if you are looking a the code just remember 4 means go back a section and 5 means run the same section again.

3

Section 3 decodes the data into the characters that make up the code after the data block. Each time it expects the stack to appear as so:

Previous query
Result of query
Number of data
Junk we shouldn't touch...

It maps each possible result (a number from 1 to 6) to one of the six valid Miniflak characters ((){}[]) and places it below the number of data with the "Junk we shouldn't touch". This gets us a stack like:

Previous query
Number of data
Junk we shouldn't touch...

From here we need to either query the next datum or if we have queried them all move to section 2. Previous query is not actually the exact query sent out but rather the query minus the number of data in the block. This is because each datum decrements the query by one so the query comes out quite mangled. To generate the next query we add a copy of the number of data and subtract one. Now our stack looks like:

Next query
Number of data
Junk we shouldn't touch...

If our next query is zero we have read all the memory needed in section 3 so we add the number of data to the query again and slap a 4 on top of the stack to move onto section 2. If the next query is not zero we put a 5 on the stack to run section 3 again.

2

Section 2 makes the block of data by querying our RAM just as section 3 does.

For the sake of brevity I will omit most of the details of how section 2 works. It is almost identical to section 3 except instead of translating each datum into one character it translates each into a lengthy chunk of code representing its entry in the RAM. When section 2 is done it calls on section 1.

1

Section one is the most simple section.

It pushes the first bit of the quine ([()]())(()()()()){({}[( and defers to section 5.

5

There is no real section 5 instead a 5 will be decremented once by each section, entering none of them and the once more by the decrement hanging around at the end of the loop. This will result in a zero and will exit the main loop terminating the program.


I hope this was clear. Please comment if you are confused about anything.

Wheat Wizard

Posted 2011-01-28T00:34:05.293

Reputation: 33 549

2Wait... so the quine of a subset is shorter than the quine of the original? – ETHproductions – 2016-12-08T23:52:17.993

@ETHproductions No, the original was golfed down to 11k – DJMcMayhem – 2016-12-09T00:14:28.447

@DJMcMayhem But isn't 6900 less than 11028? – ETHproductions – 2016-12-09T00:15:05.303

... Apparently I can't math... – DJMcMayhem – 2016-12-09T00:16:34.893

8

JavaScript (ES6 REPL), 22 bytes

f=_=>"f="+f+";f()";f()

Idea stolen from Kendall Frey but in less bytes.

Since I cannot comment on his answer because I don't have rep I decided to make a new answer.

user64039

Posted 2011-01-28T00:34:05.293

Reputation:

2Welcome to the site! – DJMcMayhem – 2017-01-02T17:56:21.867

1Save a byte with template literals: f=_=&gt;'f=${f};f()';f() (replace single quotes with backticks). – Shaggy – 2017-04-26T16:11:08.200

(f=_=&gt;*(f=${f})()*)() to save one byte (swap * with "`") – Brian H. – 2018-02-20T14:53:50.230

8

TI-BASIC

i

Where i is the imaginary number

Timtech

Posted 2011-01-28T00:34:05.293

Reputation: 11 060

1@Timtech The goal is to write the shortest quine. – mbomb007 – 2015-09-14T21:38:00.797

@mbomb007 True, updated. – Timtech – 2015-09-17T23:56:04.503

-1. That doesn't actually print 2i outside of an interactive console, does it? – nyuszika7h – 2014-04-26T15:27:23.670

@nyuszika7h Yes it does. 2i works as a program that, when run, prints 2i (because the last line that sets Ans is automatically printed). – Timtech – 2014-04-26T16:40:56.363

11@nyuszika7h Please test or research before downvoting. – Timtech – 2014-04-26T16:41:19.850

Well, now I can't undo my vote unless this answer is edited. But then couldn't you just use 2 for a 1-byte solution? – nyuszika7h – 2014-04-27T17:46:20.337

@nyuszika7h Yes, but that isn't interesting/obfuscated... – Timtech – 2014-04-27T20:35:11.567

8

JavaScript:

<script>alert(document.querySelector("script").outerHTML)</script>

It technically doesn't read its own file.

I think this is shorter and more “obfuscated”, though:

(_=$=>alert('(_='+_+')()'))()

Ryan

Posted 2011-01-28T00:34:05.293

Reputation: 4 891

1Uncaught SyntaxError: Unexpected token =&gt; in Chrome – Nakilon – 2015-01-14T09:36:38.960

6@Nakilon: Use Firefox. – Ryan – 2015-01-14T16:17:49.293

1+1 for the +_+ in the shorter version – user48538 – 2016-01-04T18:31:10.833

1Umm... the first one is actually HTML5. – Erik the Outgolfer – 2016-06-15T08:07:23.900

6It reads its own source, though. – Joey – 2011-05-12T21:15:22.640

8

J - 20 (16?) char

Seems we're missing a J entry. Trivially, any sentence that doesn't evaluate gets itself printed in the REPL, so 1 or + or +/ % # are all quines in that sense. A non-trivial quine would be one that produces specifically a string containing the source code.

',~@,~u:39',~@,~u:39

u:39 is the ASCII character 39, i.e. the single quote, and ',~@,~u:39' is a string. , is the append verb. The main verb ,~@,~ evaluates as follows:

x ,~@,~ y      
y ,~@, x       NB. x f~ y => y f x       "Passive"
,~ (y , x)     NB. x f@g y => f (x g y)  "At"
(y,x) , (y,x)  NB. f~ y => y f y         "Reflex"

So the result is 'string'string when x is string and y is the single quote, and thus this is a quine when x is ,~@,~u:39.

If we're allowed the J standard library as well, then we can write the 16 character

(,quote)'(,quote)'

which appends the quote of the string (,quote) to itself.

algorithmshark

Posted 2011-01-28T00:34:05.293

Reputation: 6 534

8

Shell echo-sed quine:

echo sed -eh -es/[\\\(\\\\\\\\\\\)\\\&\\\|]/\\\\\\\\\\\&/g -es/^/echo\\ / -es/$/\\\|/ -eG|
sed -eh -es/[\(\\\\\)\&\|]/\\\\\&/g -es/^/echo\ / -es/$/\|/ -eG

I wanted to write a sed quine, but sed can only work on its input stream, not generate output spontaneously, so this is an echo-sed quine. This 154-character quine uses command-line sed, which automatically makes it hard to read, and uses three different sed commands, as well as two sequences of eleven backslashes in a row. This quine works in bash, ksh, and sh, but not csh or tcsh.

EDIT:

A blatant, and amusing, cheat: echo $BASH_COMMAND

Another, unreasonably silly, cheat: export PROMPT_COMMAND='echo $BASH_COMMAND';$PROMPT_COMMAND

Andrew

Posted 2011-01-28T00:34:05.293

Reputation: 81

8

PHP - 54 characters (no cheating)

<?printf($p='<?printf($p=%c%s%c,39,$p,39);',39,$p,39);

(finally even shorter)

Aurel Bílý

Posted 2011-01-28T00:34:05.293

Reputation: 1 043

8

HTML + CSS 118 78 77 75 53 51 characters

<style>*{display:flex}style:before{content:'<style>

This language isn't good for quining, but it works. Invalid HTML and CSS, but it doesn't really matter.

xfix

Posted 2011-01-28T00:34:05.293

Reputation: 9 392

} isn't required – xem – 2013-12-21T19:02:13.023

1@xem: Removed '}. This abuses CSS error handling rules, but considering it's code golf, it's fine. – xfix – 2013-12-21T19:13:32.600

What browser did this work in? Running in Chrome 59 and this outputs *{display:inline;font-family:monospace}style:before{content:'&lt;style&gt; – Patrick Roberts – 2017-07-16T05:25:18.220

Why does it need to be monospaced? And if it does, using &lt;pre&gt; is faster. – RamenChef – 2017-10-27T03:00:16.380

&lt;style&gt;*{display:inline}style:before{content:'&lt;style&gt; works for less bytes. – Riker – 2018-02-20T15:30:06.460

@Riker Not sure how I missed that. Fixed. – xfix – 2018-02-21T12:17:01.647

display:flex seems to work as well. – Dennis – 2018-02-21T14:17:51.620

@Dennis thanks, fixed :) – xfix – 2018-02-22T20:13:19.273

8

Shakespeare Programming Language, 6060001 bytes

Disclaimer: I do not take credit for this, the generator was made by Florian Pommerening and Thomas Mayer.

An Epic Never-Ending Saga.

Paris, a stacky person.
Pinch, impersonates Paris.
Venus, the opposite of Paris and Pinch.
Puck, continuously speaking.
Ajax, constantly complaining.
Page, perpetually blabbing.
Ford, incessantly talking.
Viola, ceaselessly communicating.


            Act I: Prelude.

        Scene I: Best things last.

[Enter Venus and Paris]

Paris:
    Let us proceed to act V.



            Act II: Remembrance.

        Scene I: Forgetful Venus.

Paris:
    Remember nothing.
    [...]

Generator Link

Generated SPL Code

Translated C Code (requires spl.h and libspl.a from a bugfixed SPL version to compile)

Compiled binary

Oliver Ni

Posted 2011-01-28T00:34:05.293

Reputation: 6 425

This answer should be marked as community wiki, perhaps? – SuperJedi224 – 2016-12-10T23:12:15.900

@SuperJedi224 Done. Thank you. – Oliver Ni – 2016-12-11T04:37:05.227

@SuperJedi224 Community wiki is not a rep waiver.

– Dennis – 2016-12-16T04:45:46.077

Holy crap. ---- – MD XF – 2017-05-24T23:37:54.613

also this is hardly golfed – Destructible Lemon – 2017-06-08T02:13:36.897

7

RProgN, 3 bytes

0
0

Try it online!

This exploits a potential flaw in our definition of proper quine:

It must be possible to identify a section of the program which encodes a different part of the program. ("Different" meaning that the two parts appear in different positions.)

Furthermore, a quine must not access its own source, directly or indirectly.

The stack of RProgN is printed backwards, so the first 0 encodes the second 0, and vice versa.

This can be verified empirically; the program

1
2

prints

2
1

Try it online!

Dennis

Posted 2011-01-28T00:34:05.293

Reputation: 171 923

1Oh my, it's actually getting usage. I feel like a proud father. – ATaco – 2016-12-16T05:26:43.827

7

√ å ı ¥ ® Ï Ø ¿ , 9 (possibly 11) bytes

Non-competing as language post-dates the challenge

79 87  OW

Notice the double space between the 87 and the OW. This is necessary because of the way √ å ı ¥ ® Ï Ø ¿ outputs.

The O command outputs the whole of the stack as numbers

The W command outputs the whole stack as Unicode interpretations of the numbers

The 11 byte solution

The above code will output

===== OUTPUT =====

79 87  OW

==================

-----Program Execution Information-----

Code        : 79 87  OW
Inputs      : []
Stack       : (79,87)
G-Variable  : None
Byte Length : 9
Exit Status : 0
Error       : None

---------------------------------------

This is obviously not the code inputted but is outputted automatically by the interpreter. If this is disallowed, there is an 11 byte solution that only outputs the required output:

ł 79 87  OW

This will only output

ł 79 87  OW

I'm not sure if the 9 byte answer is acceptable, could someone please tell me in the comments?

caird coinheringaahing

Posted 2011-01-28T00:34:05.293

Reputation: 6 705

1This is a much less trivial quine than usual - nice! – isaacg – 2017-03-20T04:46:12.667

That looks valid (9 byte). I mean the other stuff is just interpreter items that are always there – Christopher – 2017-05-21T12:29:44.527

this isn't non-competing because this is a catalogue and any language is fine – Destructible Lemon – 2017-05-21T23:17:24.260

@DestructibleLemon I'm a stickler to explicit rules and it doesn't say that in the question. It's fine though. – caird coinheringaahing – 2017-05-22T06:10:58.390

7

Klein, 11 + 6 = 17 bytes

3 additional bytes for the topology argument 001 and another 3 for ASCII output -A.

:?/:2+@> "

Try it online!

Let's start with the topology. The 1 at the end indicates that the north and south edges of the code are mapped to each other in reverse. So if the IP leaves the code through the south edge in the leftmost column, it will re-enter through the north edge in the rightmost column. We use this to skip to the end of the program.

:             Duplicate the top of the stack (implicitly zero).
?             Skip the next command if that value is non-zero (which it isn't).
/             Reflect the IP north.
              The IP leaves through the north edge in the third column from
              the left, so it will re-enter from the south edge in the third
              column from the right.
>             Move east.
":?/:2+@> "   Push the code points of the program, except for the quote itself
              to the stack.
:             Duplicate the top of the stack, now a 32 (the space).
?             Skip the next command (the /).
:             Duplicate the top of the stack again.
2+            Add 2, to turn the space into a quote.
@             Terminate the program.

Martin Ender

Posted 2011-01-28T00:34:05.293

Reputation: 162 549

7

Charcoal, 64 31 32 (because of newlines)

My first answer in charcoal ever!

Similar to /// and other languages, just straight up ascii would print itself. however that is not payload and also boring, so here is an actual quine.

taking a golfing tip from Ascii-only, and my realisation that the second looping is pointless, I have reduced by >50%

A´α´´´A´F´α´⁺´´´´´ι´αα´AFα⁺´´ια

Try it online!

Explanation

(thanks to ascii-only for making most of this.)

A                     α            Assign to a
 ´α´´´A´F´α´⁺´´´´´ι´α             "α´AFα⁺´´ια", but with ´ escape character with each
                                    character
                                    these are the variable being assigned to, and the
                                    rest of the program that is not the string.

                        ´A         Print A to the grid. current grid: "A"
                           Fα⁺´´ι  For each character in a, print ´ + character
                                    this results in the escaped version of the string
                                    which is the literal string that is assigned at the 
                                    start. current grid state: "A´α´´´A´F´α´⁺´´´´´ι´α"

                                  α Print a ("α´AFα⁺´´ια"), which is the commands after
                                    the string assignment. final grid state vvv:
                                                 "A´α´´´A´F´α´⁺´´´´´ι´αα´AFα⁺´´ια"

[implicitly print the grid: "A´α´´´A´F´α´⁺´´´´´ι´αα´AFα⁺´´ια", the source, with a trailing newline]

Destructible Lemon

Posted 2011-01-28T00:34:05.293

Reputation: 4 669

Wish I was better at reading Charcoal. Looking forward to that explanation :) – Emigna – 2017-05-19T10:11:46.350

1I can hardly read this myself :P – Destructible Lemon – 2017-05-19T10:12:55.920

You can leave off the final closing double angle bracket, saving 3 bytes: A´α´´´A´F´L´α´«´´´´´§´α´ι´»´F´L´α´«´§´α´ια´AFLα«´´§αι»FL᫧αι – ASCII-only – 2017-05-19T10:33:55.217

Oh wait you can also iterate over the string directly. 37 bytes: A´α´´´A´F´α´⁺´´´´´ι´F´α´ια´AFα⁺´´ιFαι – ASCII-only – 2017-05-19T10:38:03.893

@ASCII-only couldn't this be one byte? f – Christopher – 2017-05-19T14:11:25.653

https://tio.run/nexus/charcoal#@5/2/z8A – Christopher – 2017-05-19T14:11:45.687

It is "A quine is a non-empty computer program which takes no input and produces a copy of its own source code as its only output." – Christopher – 2017-05-19T14:12:09.013

@Christopher ... That way It isn't payload-capable so it actually isn't a quine (You can't have commands in the payload) – ASCII-only – 2017-05-20T00:02:07.313

@ASCII-only they defined their own quine definition so it does not need to be payload-capable. – Christopher – 2017-05-20T19:35:47.837

@Christopher Well if it's valid feel free to post a solution – ASCII-only – 2017-05-20T23:58:57.480

@Christopher That f suggestion seems to print an extra newline, so isn't a quine. But if it didn't, it would probably run afoul of the rule that there must be a part of the program that encodes a different part. – Ørjan Johansen – 2017-05-21T02:28:08.577

@ØrjanJohansen well adding a newline to the code works. But if it is not "encoding" what about the quine in golfscript? (1 and a newline) – Christopher – 2017-05-21T12:27:21.303

@Christopher Oh, when I tried adding a newline it seemed to get stuck, I didn't try waiting until TIO timed out though. If I recall correctly the argument for golfscript is that the newline is not encoding itself. – Ørjan Johansen – 2017-05-21T18:28:59.013

@ØrjanJohansen mine ran just fine. – Christopher – 2017-05-21T18:38:32.277

7

C, 77 chars

Maybe the easiest one in C.

main(){char*c="main(){char*c=%c%s%c;printf(c,34,c,34);}";printf(c,34,c,34);}

34 is the ASCII decimal for ".

efermat

Posted 2011-01-28T00:34:05.293

Reputation: 127

I count 76 bytes. – Lynn – 2017-01-18T15:06:57.490

@Lynn He must have used wc and forgot to exclude the trailing newline :P – MD XF – 2017-05-26T16:32:45.750

7

C, 78 chars

#define Q(S)char*q=#S;S
Q(main(){printf("#define Q(S)char*q=#S;S\nQ(%s)",q);})

This version is shorter than the familiar 79-character C quine and also doesn't assume ASCII. It does still assume that it's safe to not include stdio.h. (Adding an explicit declaration of printf() brings the length up to 103 chars.)

breadbox

Posted 2011-01-28T00:34:05.293

Reputation: 6 443

7

MUMPS, 9 bytes

R w $T(R)

This may fall afoul of the "you can't just read the source file and print it" restriction. Let me explain why I say may.

The line of code you see above constitutes a complete MUMPS "routine" (named R), which is sort of like a single source file in a conventional C-like language... but not quite.

The way MUMPS stores its routines is peculiar among programming languages. Routines are not files living in a regular filesystem. Instead, they are data structures internal to the database itself. The line of code I've supplied above is actually stored as part of the MUMPS global named ^ROUTINE (globals are basically trees). The "R" subtree (in MUMPS parlance, "subscript") of that global would look something like this:

^ROUTINE("R",0)=1
^ROUTINE("R",1)="R w $T(R)"

The first entry is the number of lines of code in the routine. The subsequent entries are the lines of code in the routine itself.

Why do I bring this up? Well, this means that in MUMPS, the routines themselves are first-class entries in the database! One can edit routines by directly manipulating the contents of the ^ROUTINE global, just as one can edit any other global. (Indeed, at the most basic level, if your MUMPS environment doesn't come with an editor, you must invent one for yourself that will edit the ^ROUTINE global on your behalf.)

The ability to manipulate routines in MUMPS code is so important that the standard even defines a function whose explicit purpose is to tell you what code is found at a given line of a given routine. That function is named $T[EXT], and if you give it a pointer to a line of code, it will return the code present at that location.

And that's what we do here. We w[rite] the result of a call to $TEXT(R) - that is, the contents of the line at the first line of the routine R - to the output stream, and since R is only one line long, that makes the program a quine.

This program involves no file IO at all. The whole thing is internal to the MUMPS environment. I claim that this is interesting enough to count as a legitimate quine, despite the fact that this has a surface-level resemblance to a program that just reads and prints the source file.

senshin

Posted 2011-01-28T00:34:05.293

Reputation: 611

7

JavaScript (Firefox), 44 40 bytes

eval(e="alert('eval(e='+uneval(e)+')')")

Not sure how I haven't thought of this before; it's basically exactly the same as the standard function quine (f=_=>alert('f='+f+';f()'))(), but with a string. Funnily enough, I only thought of this while attempting to demonstrate how similar string-based quines are to function-based quines...

A cross-browser version (avoiding uneval) is 72 bytes:

Q='"';q="'";eval(e="alert('Q='+q+Q+q+';q='+Q+q+Q+';eval(e='+Q+e+Q+')')")

Or ES6, 50 bytes:

Q='"';eval(e="alert(`Q='${Q}';eval(e=${Q+e+Q})`)")

Previous answer, 74 bytes

".replace(/.+/,x=>alert(uneval(x)+x))".replace(/.+/,x=>alert(uneval(x)+x))

Simply takes the whole string and prepends its unevaluated form. Note: uneval may not work in all browsers. Here's a cross-browser version at 113 bytes:

".replace(/.+/,x=>alert(q+x+q+x.replace(/\\d/g,q)),q='1')".replace(/.+/,x=>alert(q+x+q+x.replace(/\d/g,q)),q='"')

Original answer, 118 bytes

Now, this certainly isn't a winner, but AFAIK, this is the first ever non-source-reading quine in JS! :D

alert([A=",A,A].join(String.fromCharCode(34)).slice(49,-9))alert([A=",A,A].join(String.fromCharCode(34)).slice(49,-9))

How does it work, you ask? Well, if you look closely, you will see that it's really the same thing repeated twice:

alert([A=",A,A].join(String.fromCharCode(34)).slice(49,-9))

The logic here is to A) place a copy of the real code in a string, and B) orient this string so the program can be split into two identical halves. But how could we get those quotes in there? Well, we could either navigate an insanely difficult path of inserting backslashes before a quote, or use the (painfully long) workaround String.fromCharCode(34) to retrieve one. The latter method is what I chose.

So, this code puts three copies of the string

,A,A].join(String.fromCharCode(34)).slice(49,-9))alert([A=

in an array, then joins them with quotes (using the mentioned workaround):

,A,A].join(String.fromCharCode(34)).slice(49,-9))alert([A=",A,A].join(String.fromCharCode(34)).slice(49,-9))alert([A=",A,A].join(String.fromCharCode(34)).slice(49,-9))alert([A=

and finally, slices off the unnecessary characters from the beginning and end:

,A,A].join(String.fromCharCode(34)).slice(49,-9))alert([A=",A,A].join(String.fromCharCode(34)).slice(49,-9))alert([A=",A,A].join(String.fromCharCode(34)).slice(49,-9))alert([A=
alert([A=",A,A].join(String.fromCharCode(34)).slice(49,-9))alert([A=",A,A].join(String.fromCharCode(34)).slice(49,-9))

This leaves us with the text of the original program, which is alerted to the user.

If the alert is unnecessary, here's a 104-byte alternative:

[A=",A,A].join(String.fromCharCode(34)).slice(48,-3)[A=",A,A].join(String.fromCharCode(34)).slice(48,-3)

ETHproductions

Posted 2011-01-28T00:34:05.293

Reputation: 42 391

7

Japt, 10 bytes

"iQ ²"iQ ²

Here's how this works:

"iQ ²"      // Take this string.        iQ ²
      iQ    // Insert a quote.          "iQ ²
         ²  // Double.                  "iQ ²"iQ ²
            // Implicitly output.

Test it online!

Of course, any number literal is also a quine because of implicit output.

ETHproductions

Posted 2011-01-28T00:34:05.293

Reputation: 42 391

Does Japt add a newline at the end of implicit output? – CalculatorFeline – 2016-03-23T04:28:20.647

@CalculatorFeline Nope. – ETHproductions – 2016-09-07T02:24:12.887

7

Factor - 74 69 65 bytes

Works on the listener (REPL):

USE: formatting [ "USE: formatting %u dup call" printf ] dup call

This is my first ever quine, I'm sure there must be a shorter one! Already shorter. Now I'm no longer sure... (bad pun attempt)

What it does is:

  • USE: formatting import the formatting vocabulary to use printf
  • [ "U... printf ] create a quotation (or lambda, or block) on the top of the stack
  • dup call duplicate it, and call it

The quotation takes the top of the stack and embeds it into the string as a literal.

Thanks, cat! -> shaved 2 4 more bytes :D

fede s.

Posted 2011-01-28T00:34:05.293

Reputation: 895

1

Welcome to the site. This is a really good answer; however most people replace their old code with the new code and use the edit history to see the old code. You have, however, included a code breakdown and explanation, which not many people do on their first answer, so for that: +1.

– wizzwizz4 – 2016-02-14T09:03:07.900

@wizzwizz4 Thanks for the advice and up! Actually my 2nd answer, but first quine ever and first edit on PCG. – fede s. – 2016-02-14T22:07:11.590

Well, if you ever need help, feel free to ping me. – wizzwizz4 – 2016-02-14T22:11:22.557

I never realised a quine was so simple in Factor! Also, the bottom, shorter one can be a single line for 65 bytes, because you don't need the trailing newline: USE: formatting [ "USE: formatting %u dup call" printf ] dup call – cat – 2016-05-17T22:55:22.420

Thanks, @cat Just assumed it expected EOL, but this makes more sense actually! – fede s. – 2016-05-17T23:07:57.073

@fedes. No problem c: you don't need the \n at the end of the format string, also – cat – 2016-05-17T23:09:17.497

@cat that happens when you try to read faster than you can think :/ added that. Too bad your trick of skipping ws after strings doesn't work here. pretty-printer adds the space by itself, so it's no longer a quine. (Same prob. with Smalltalk) – fede s. – 2016-05-17T23:24:42.880

@fedes. Hm, interesting, I think this is as short as it can go – cat – 2016-05-17T23:29:33.607

7

S.I.L.O.S, 3057 bytes

A = 99
def S set 
S A 112
A + 1
S A 114
A + 1
S A 105
A + 1
S A 110
A + 1
S A 116
A + 1
S A 76
A + 1
S A 105
A + 1
S A 110
A + 1
S A 101
A + 1
S A 32
A + 1
S A 65
A + 1
S A 32
A + 1
S A 61
A + 1
S A 32
A + 1
S A 57
A + 1
S A 57
A + 1
S A 10
A + 1
S A 72
A + 1
S A 32
A + 1
S A 61
A + 1
S A 32
A + 1
S A 56
A + 1
S A 51
A + 1
S A 10
A + 1
S A 112
A + 1
S A 114
A + 1
S A 105
A + 1
S A 110
A + 1
S A 116
A + 1
S A 32
A + 1
S A 100
A + 1
S A 101
A + 1
S A 102
A + 1
S A 32
A + 1
S A 10
A + 1
S A 112
A + 1
S A 114
A + 1
S A 105
A + 1
S A 110
A + 1
S A 116
A + 1
S A 67
A + 1
S A 104
A + 1
S A 97
A + 1
S A 114
A + 1
S A 32
A + 1
S A 72
A + 1
S A 10
A + 1
S A 112
A + 1
S A 114
A + 1
S A 105
A + 1
S A 110
A + 1
S A 116
A + 1
S A 76
A + 1
S A 105
A + 1
S A 110
A + 1
S A 101
A + 1
S A 32
A + 1
S A 32
A + 1
S A 83
A + 1
S A 32
A + 1
S A 10
A + 1
S A 67
A + 1
S A 32
A + 1
S A 61
A + 1
S A 32
A + 1
S A 57
A + 1
S A 57
A + 1
S A 10
A + 1
S A 66
A + 1
S A 32
A + 1
S A 61
A + 1
S A 32
A + 1
S A 103
A + 1
S A 101
A + 1
S A 116
A + 1
S A 32
A + 1
S A 67
A + 1
S A 10
A + 1
S A 108
A + 1
S A 98
A + 1
S A 108
A + 1
S A 68
A + 1
S A 10
A + 1
S A 67
A + 1
S A 32
A + 1
S A 43
A + 1
S A 32
A + 1
S A 49
A + 1
S A 10
A + 1
S A 112
A + 1
S A 114
A + 1
S A 105
A + 1
S A 110
A + 1
S A 116
A + 1
S A 67
A + 1
S A 104
A + 1
S A 97
A + 1
S A 114
A + 1
S A 32
A + 1
S A 72
A + 1
S A 10
A + 1
S A 112
A + 1
S A 114
A + 1
S A 105
A + 1
S A 110
A + 1
S A 116
A + 1
S A 32
A + 1
S A 32
A + 1
S A 65
A + 1
S A 32
A + 1
S A 10
A + 1
S A 112
A + 1
S A 114
A + 1
S A 105
A + 1
S A 110
A + 1
S A 116
A + 1
S A 73
A + 1
S A 110
A + 1
S A 116
A + 1
S A 32
A + 1
S A 66
A + 1
S A 10
A + 1
S A 112
A + 1
S A 114
A + 1
S A 105
A + 1
S A 110
A + 1
S A 116
A + 1
S A 76
A + 1
S A 105
A + 1
S A 110
A + 1
S A 101
A + 1
S A 32
A + 1
S A 65
A + 1
S A 32
A + 1
S A 43
A + 1
S A 32
A + 1
S A 49
A + 1
S A 10
A + 1
S A 66
A + 1
S A 32
A + 1
S A 61
A + 1
S A 32
A + 1
S A 103
A + 1
S A 101
A + 1
S A 116
A + 1
S A 32
A + 1
S A 67
A + 1
S A 10
A + 1
S A 105
A + 1
S A 102
A + 1
S A 32
A + 1
S A 66
A + 1
S A 32
A + 1
S A 68
A + 1
S A 10
A + 1
S A 70
A + 1
S A 32
A + 1
S A 61
A + 1
S A 32
A + 1
S A 57
A + 1
S A 57
A + 1
S A 10
A + 1
S A 69
A + 1
S A 32
A + 1
S A 61
A + 1
S A 32
A + 1
S A 103
A + 1
S A 101
A + 1
S A 116
A + 1
S A 32
A + 1
S A 70
A + 1
S A 10
A + 1
S A 108
A + 1
S A 98
A + 1
S A 108
A + 1
S A 71
A + 1
S A 10
A + 1
S A 70
A + 1
S A 32
A + 1
S A 43
A + 1
S A 32
A + 1
S A 49
A + 1
S A 10
A + 1
S A 112
A + 1
S A 114
A + 1
S A 105
A + 1
S A 110
A + 1
S A 116
A + 1
S A 67
A + 1
S A 104
A + 1
S A 97
A + 1
S A 114
A + 1
S A 32
A + 1
S A 69
A + 1
S A 10
A + 1
S A 69
A + 1
S A 32
A + 1
S A 61
A + 1
S A 32
A + 1
S A 103
A + 1
S A 101
A + 1
S A 116
A + 1
S A 32
A + 1
S A 70
A + 1
S A 10
A + 1
S A 105
A + 1
S A 102
A + 1
S A 32
A + 1
S A 69
A + 1
S A 32
A + 1
S A 71
A + 1
printLine A = 99
H = 83
print def 
printChar H
printLine  S 
C = 99
B = get C
lblD
C + 1
printChar H
print  A 
printInt B
printLine A + 1
B = get C
if B D
F = 99
E = get F
lblG
F + 1
printChar E
E = get F
if E G

Try it online!

I am ashamed to say this took me a while to write even though most of it was generated by another java program. Thanks to @MartinEnder for helping me out. This is the first quine I have ever written. Credits go to Leaky Nun for most of the code. I "borrowed his code" which was originally inspired by mine. My answer is similar to his, except it shows the "power" of the preprocessor. Hopefully this approach can be used to golf of bytes if done correctly. The goal was to prevent rewriting the word "set" 100's of times.
Please check out his much shorter answer!

Rohan Jhunjhunwala

Posted 2011-01-28T00:34:05.293

Reputation: 1 878

How does this work? – Leaky Nun – 2016-08-26T18:44:27.637

It's borked from my understanding @LeakyNun but it essentially writes it source code to the memory buffer, and then prints out commands to write itself to the memory buffer, and then writes itself out – Rohan Jhunjhunwala – 2016-08-26T18:46:11.093

From my point of view this is not a quine? – Leaky Nun – 2016-08-26T18:55:58.237

@LeakyNun it's borked... let me fix... should I delete, fix and undelete? – Rohan Jhunjhunwala – 2016-08-26T18:58:47.053

7

S.I.L.O.S, 2642 2593 bytes

Credits to Rohan Jhunjhunwala for the algorithm.

A = 99
set A 112
A + 1
set A 114
A + 1
set A 105
A + 1
set A 110
A + 1
set A 116
A + 1
set A 76
A + 1
set A 105
A + 1
set A 110
A + 1
set A 101
A + 1
set A 32
A + 1
set A 65
A + 1
set A 32
A + 1
set A 61
A + 1
set A 32
A + 1
set A 57
A + 1
set A 57
A + 1
set A 10
A + 1
set A 67
A + 1
set A 32
A + 1
set A 61
A + 1
set A 32
A + 1
set A 57
A + 1
set A 57
A + 1
set A 10
A + 1
set A 66
A + 1
set A 32
A + 1
set A 61
A + 1
set A 32
A + 1
set A 103
A + 1
set A 101
A + 1
set A 116
A + 1
set A 32
A + 1
set A 67
A + 1
set A 10
A + 1
set A 108
A + 1
set A 98
A + 1
set A 108
A + 1
set A 68
A + 1
set A 10
A + 1
set A 67
A + 1
set A 32
A + 1
set A 43
A + 1
set A 32
A + 1
set A 49
A + 1
set A 10
A + 1
set A 112
A + 1
set A 114
A + 1
set A 105
A + 1
set A 110
A + 1
set A 116
A + 1
set A 32
A + 1
set A 115
A + 1
set A 101
A + 1
set A 116
A + 1
set A 32
A + 1
set A 65
A + 1
set A 32
A + 1
set A 10
A + 1
set A 112
A + 1
set A 114
A + 1
set A 105
A + 1
set A 110
A + 1
set A 116
A + 1
set A 73
A + 1
set A 110
A + 1
set A 116
A + 1
set A 32
A + 1
set A 66
A + 1
set A 10
A + 1
set A 112
A + 1
set A 114
A + 1
set A 105
A + 1
set A 110
A + 1
set A 116
A + 1
set A 76
A + 1
set A 105
A + 1
set A 110
A + 1
set A 101
A + 1
set A 32
A + 1
set A 65
A + 1
set A 32
A + 1
set A 43
A + 1
set A 32
A + 1
set A 49
A + 1
set A 10
A + 1
set A 66
A + 1
set A 32
A + 1
set A 61
A + 1
set A 32
A + 1
set A 103
A + 1
set A 101
A + 1
set A 116
A + 1
set A 32
A + 1
set A 67
A + 1
set A 10
A + 1
set A 105
A + 1
set A 102
A + 1
set A 32
A + 1
set A 66
A + 1
set A 32
A + 1
set A 68
A + 1
set A 10
A + 1
set A 70
A + 1
set A 32
A + 1
set A 61
A + 1
set A 32
A + 1
set A 57
A + 1
set A 57
A + 1
set A 10
A + 1
set A 69
A + 1
set A 32
A + 1
set A 61
A + 1
set A 32
A + 1
set A 103
A + 1
set A 101
A + 1
set A 116
A + 1
set A 32
A + 1
set A 70
A + 1
set A 10
A + 1
set A 108
A + 1
set A 98
A + 1
set A 108
A + 1
set A 71
A + 1
set A 10
A + 1
set A 70
A + 1
set A 32
A + 1
set A 43
A + 1
set A 32
A + 1
set A 49
A + 1
set A 10
A + 1
set A 112
A + 1
set A 114
A + 1
set A 105
A + 1
set A 110
A + 1
set A 116
A + 1
set A 67
A + 1
set A 104
A + 1
set A 97
A + 1
set A 114
A + 1
set A 32
A + 1
set A 69
A + 1
set A 10
A + 1
set A 69
A + 1
set A 32
A + 1
set A 61
A + 1
set A 32
A + 1
set A 103
A + 1
set A 101
A + 1
set A 116
A + 1
set A 32
A + 1
set A 70
A + 1
set A 10
A + 1
set A 105
A + 1
set A 102
A + 1
set A 32
A + 1
set A 69
A + 1
set A 32
A + 1
set A 71
A + 1
printLine A = 99
C = 99
B = get C
lblD
C + 1
print set A 
printInt B
printLine A + 1
B = get C
if B D
F = 99
E = get F
lblG
F + 1
printChar E
E = get F
if E G

Try it online!

Leaky Nun

Posted 2011-01-28T00:34:05.293

Reputation: 37 559

Good job! May I "borrow this post for my github repository? – Rohan Jhunjhunwala – 2016-08-26T19:12:34.010

@RohanJhunjhunwala Sure. – Leaky Nun – 2016-08-26T19:18:44.527

7

Bash, 35 28 20 bytes

trap -- 'trap' EXIT

@Dennis pointed out that even the -p flag is not necessary, and trap will print the trap strings unqualified, which helped save another 8 bytes, and brought about another quine:

Zsh, 18 bytes

trap -- trap EXIT

Zsh trap does not print the single quotes, which makes it incompatible with the bash version, but also allows you to save another 2 bytes for the zsh-only version. Again, though, dash does not show this behavior and trap does not print anything.

Bash, 19 bytes

Another, just barely shorter, and much less interesting bash quine:

echo $BASH_COMMAND

Thankfully the lack of single quotes mean that in zsh, trap is still shorter, which is important because the $BASH_COMMAND variable does not exist. Additionally, I'd be tempted to count this as 'reading the source' but that might be because I like the trap one so much.

Bash 28 byte submission

trap -- 'trap -p EXIT' EXIT

Just realized that the echo statement could be cut out entirely, trap -p simply prints the trap statement in this format (saved another 7 bytes).

Compatibility: This must be in a script file, trap does not work as expected on the command line, and its bash-only: bourne shell/ash/dash does not support the -p flag to trap (obviously instrumental to the quine).

Original 35 byte submission:

trap -- 'echo `trap -p EXIT`' EXIT

A much farther golf of @ormaaj's trap-based solution. Shaves off 1 character by switching to backticks, 2 more because the quotes around the echo body are not necessary, and 9 characters by switching to echo. The real magic though, is switching from a DEBUG trap to EXIT. This saves 2 characters just because EXIT is shorter, and 3 more because you do not need to call : or print it (and it drastically simplified the escaping needed for echo).

I'm not 100% sure whether this counts as 34 or 35 bytes, as echo prints a trailing newline and I'm not sure whether its a true quine if I don't include a trailing newline in the source. I called it 35 bytes to be more safe/truthful, but I'd love to know what a real ruling on this is.

Link to @ormaaj's original solution. (If I had enough reputation to post these golfs as a comment on the original post, I would have. My apologies if any of this breaks convention.)

LinusKrom

Posted 2011-01-28T00:34:05.293

Reputation: 93

Welcome to Programming Puzzles & Code Golf, and congrats on a really neat quine! 1. trap -- 'trap' EXIT should work as well. 2. The trailing newline has to be counted, since the program wouldn't be a quine without it. 3. Your solution is different enough to be posted in a separate answer. No worries. – Dennis – 2016-10-17T20:24:55.947

What was the original answer? – CalculatorFeline – 2017-01-28T02:13:02.103

My original answer is the 35 byte one at the end of this post, with trap and echo. As I edited it and golfed my solution down farther, I added new solutions and comments to the top of the post. – LinusKrom – 2017-01-29T04:15:40.737

7

05AB1E, 14 bytes

Shortest proper 05AB1E quine?

0"D34çý"D34çý

With trailing newline.

Try it online!

Explanation:

0              # Push '0'
                   # Stack: ['0']
 "D34çý"       # Push 'D34çý'
                   # Stack: ['0', 'D34çý']
        D      # Duplicate
                   # Stack: ['0', 'D34çý', 'D34çý']
         34ç   # Push '"'
                   # Stack: ['0', 'D34çý', 'D34çý', '"']
            ý  # Join rest of the stack with '"'
                   # Stack: ['0"D34çý"D34çý']
               # Implicit print

Oliver Ni

Posted 2011-01-28T00:34:05.293

Reputation: 6 425

Isn't 1 also a proper quine? – ovs – 2017-01-15T19:24:47.430

@ovs Not by our standard definition.

– ETHproductions – 2017-01-25T16:37:32.623

6

Husk, 8 bytes

S+s"S+s"

Try it online!

Husk is a new golfing functional language created by me and Zgarb. It is based on Haskell, but has an intelligent inferencer that can "guess" the intended meaning of functions used in a program based on their possible types.

Explanation

This is a quite simple program, composed by just three functions:

S is the S combinator from SKI (typed) combinator calculus: it takes two functions and a third value as arguments and applies the first function to the value and to the second function applied to that value (in code: S f g x = f x (g x)).

This gives us +"S+s"(s"S+s"). s stands for show, the Haskell function to convert something to a string: if show is applied to a string, special characters in the string are escaped and the whole string is wrapped in quotes.

We get then +"S+s""\"S+s\"". Here, + is string concatenation; it could also be numeric addition, but types wouldn't match so the other meaning is chosen by the inferencer.

Our result is then "S+s\"S+s\"", which is a string that gets printed simply as S+s"S+s".

Leo

Posted 2011-01-28T00:34:05.293

Reputation: 6 873

6

C (gcc), 78 70 66 62 bytes

Minus 4 bytes thanks to MD XF (reusing first argument of printf)!

There are a few unprintables in this answer, replaced with ?.

main(){printf("main(){printf(%c%s%1$c,34,'@??');}",34,'@??');}

Here's an xxd:

00000000: 6d61 696e 2829 7b70 7269 6e74 6628 226d  main(){printf("m
00000010: 6169 6e28 297b 7072 696e 7466 2825 6325  ain(){printf(%c%
00000020: 7325 3124 632c 3334 2c27 4005 9027 293b  s%1$c,34,'@..');
00000030: 7d22 2c33 342c 2740 0590 2729 3b7d       }",34,'@..');}

Here's a bash script to generate and execute the program.

62 bytes, part 2

Here's a version that I have tested on my windows machine on gcc (ANSI encoded):

main(){printf("main(){printf(%c%s%1$c,34,'@@0');}",34,'@@0');}

Here's the output:

C:\Users\Conor O'Brien\Documents
λ xxd test.c
00000000: 6d61 696e 2829 7b70 7269 6e74 6628 226d  main(){printf("m
00000010: 6169 6e28 297b 7072 696e 7466 2825 6325  ain(){printf(%c%
00000020: 7325 3124 632c 3334 2c27 4040 3027 293b  s%1$c,34,'@@0');
00000030: 7d22 2c33 342c 2740 4030 2729 3b7d       }",34,'@@0');}

C:\Users\Conor O'Brien\Documents
λ cat test.c
main(){printf("main(){printf(%c%s%1$c,34,'@@0');}",34,'@@0');}
C:\Users\Conor O'Brien\Documents
λ wc test.c -c
62 test.c

C:\Users\Conor O'Brien\Documents
λ gcc test.c -o test
test.c:1:1: warning: return type defaults to 'int' [-Wimplicit-int]
 main(){printf("main(){printf(%c%s%1$c,34,'@@0');}",34,'@@0');}
 ^
test.c: In function 'main':
test.c:1:8: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
 main(){printf("main(){printf(%c%s%1$c,34,'@@0');}",34,'@@0');}
        ^
test.c:1:8: warning: incompatible implicit declaration of built-in function 'printf'
test.c:1:8: note: include '<stdio.h>' or provide a declaration of 'printf'
test.c:1:55: warning: multi-character character constant [-Wmultichar]
 main(){printf("main(){printf(%c%s%1$c,34,'@@0');}",34,'@@0');}
                                                       ^

C:\Users\Conor O'Brien\Documents
λ test
main(){printf("main(){printf(%c%s%1$c,34,'@@0');}$c,34,'@@0');}
C:\Users\Conor O'Brien\Documents
λ

66 bytes

main(){printf("main(){printf(%c%s%1$c,34,4195728);}",34,4195728);}

I have no idea why this works, 100% honest here. But dang, is it short. Only 6 bytes longer than the current best.

Try it online!

70 bytes

main(){printf("main(){printf(%c%s%c,34,4195728,34);}",34,4195728,34);}

Try it online!

78 bytes

main(){printf("main(){printf(%c%s%c,34,%c%c+8,34,34,34);}",34,""+8,34,34,34);}

Try it online!

Conor O'Brien

Posted 2011-01-28T00:34:05.293

Reputation: 25 859

66 bytes – MD XF – 2017-07-25T04:46:44.550

It works because printf is very weakly typed, so your integer constant gets interpreted as the actual pointer address of the format string constant. Very implementation-dependent, I tried it on a different Linux machine and even there I needed to adjust the numbers. – Ørjan Johansen – 2017-07-25T06:21:52.050

@ØrjanJohansen Thanks, I figured it had something to do with addressing. – Conor O'Brien – 2017-07-25T16:39:57.207

Aha, you found out how to get it down to 62 non-locally! – MD XF – 2017-07-25T17:03:24.393

@MDXF Yes I did :> – Conor O'Brien – 2017-07-25T17:15:21.840

@ConorO'Brien Also, 63 bytes without using wide-char magic

– MD XF – 2017-07-25T17:28:39.647

6

Implicit, 20 bytes

«@171%@187»@171%@187

This didn't work in older versions of Implicit.

Try it online!

How it works

«@171%@187»           Push the string '@171%@187' on the stack. Let's call it s.
           @171       Print '«' (char code 171), without pushing it on the stack.
               %      Print s without popping it from the stack.
                @187  Print '»' (char code 171), without pushing it on the stack.
                      (implicit) Print the top of the stack: s.

Implicit, 26 bytes

«:171,::187,"»:171,::187,"

Try it online!

How it works

«:171,::187,"»              Push the string ':171,::187,"' on the stack.
                            Let's call it s.
              :171          Push 171 (code point of «).
                  ,         Swap s and 171.
                   :        Push a copy of s.
                    :187    Push 187 (code point of »).
                        ,   Swap the copy of s and ».
                         "  Combine the entire stack into a string.

Dennis

Posted 2011-01-28T00:34:05.293

Reputation: 171 923

1+1, got the same solution not long after. – ATaco – 2017-09-22T02:31:36.350

6

Befunge 98 - 17 11 characters

<@,+1!',k9"

Or if using g is allowed:

Befunge 98 - 12 10

<@,g09,k8"

Justin

Posted 2011-01-28T00:34:05.293

Reputation: 17 266

Explanation for why using g may not be allowed? – MD XF – 2017-06-09T23:56:27.500

@MDXF g is arguably reading the source code. Befunge copies the code to the execution space and g reads the character at the x, y position in the execution space – Justin – 2017-06-11T06:50:08.673

6

Clojure, 91 bytes

((fn [x] (list x (list (quote quote) x))) (quote (fn [x] (list x (list (quote quote) x)))))

mikera

Posted 2011-01-28T00:34:05.293

Reputation: 843

6

JavaScript (ES6), 28 26 bytes

Run this code in Firefox 34+ (currently in Aurora)'s Web console

(f=x=>alert`(f=${f})()`)()

Optimizer

Posted 2011-01-28T00:34:05.293

Reputation: 23 401

Hmm... doesn't work in the latest version of Firefox (it outputs (f=,)()), I believe you'd have to put the template in parentheses. – ETHproductions – 2017-08-11T19:34:15.330

@rafe-ketler - I believe that this is the shortest ES6 version now :) – Optimizer – 2014-09-13T22:50:04.483

6

Commodore Basic, 54 41 characters

1R─A$:?A$C|(34)A$:D♠"1R─A$:?A$C|(34)A$:D♠

Based on DLosc's QBasic quine, but modified to take advantage of Commodore Basic's shortcut forms. In particular, the shorter version of CHR$(34) makes using it directly for quotation marks more efficient than defining it as a variable.

As usual, I've made substitutions for PETSCII characters that don't appear in Unicode: = SHIFT+A, = SHIFT+E, | = SHIFT+H.

Edit: You know what? If a string literal ends at the end of a line, the Commodore Basic interpreter will let you leave out the trailing quotation mark. Golfed off 13 characters.

Alternatively, if you want to skirt the spirit of the rules,

1 LIST

LIST is an instruction that prints the current program's code. It is intended for use in immediate mode, but like all immediate-mode commands, it can be used in a program (eg. 1 NEW is a self-deleting program). Nothing shorter is possible: dropped spaces or abbreviated forms get expanded by the interpreter and displayed at full length.

Mark

Posted 2011-01-28T00:34:05.293

Reputation: 1 896

Its not opening the file and reading its input, but I do agree that this is a bit cheaty. – YoYoYonnY – 2015-02-26T21:34:15.573

@MartinBüttner, is the new version better? – Mark – 2015-02-27T07:53:14.560

@Mark I can't read that, but it looks like a quine to me. ;) – Martin Ender – 2015-02-27T09:06:13.900

@YoYoYonnY It reads its source, tho. – Erik the Outgolfer – 2016-06-28T21:54:27.790

6

TECO, 20 bytes

<Tab>V27:^TJDV<Esc>V27:^TJDV

The <Esc> should be replaced with ASCII 0x1B, and the <Tab> with 0x09.

  • <Tab>V27:^TJDV<Esc> inserts the text <Tab>V27:^TJDV. This is not because there is a text insertion mode which TECO starts in by default. Instead, <Tab> text <Esc> is a special insertion command which inserts a tab, and then the text. A string whose own initial delimiter is part of the text -- very handy.
  • V prints the current line.
  • 27:^T prints the character with ASCII code 27 without the usual conversion to a printable representation.
  • J jumps to the beginning of the text.
  • D deletes the first character (the tab).
  • V prints the line again.

feersum

Posted 2011-01-28T00:34:05.293

Reputation: 26 090

6

QBasic, 76 (110) 54 (72)

Tested with QB64 on Windows 7, with auto-formatting turned off.

READ a$:?a$;:WRITE a$:DATA"READ a$:?a$;:WRITE a$:DATA"

: is a statement separator, and ? is a shortcut for PRINT. The main trick here is using DATA and READ so we don't have to split the string up to add the quotes. Edit: I learned this week about the WRITE command, which outputs strings wrapped in double-quotes--a significant byte-saver here!

Since actual QBasic doesn't let you turn off auto-formatting, here's the same thing with proper formatting in 72 bytes:

READ x$: PRINT x$;: WRITE x$: DATA "READ x$: PRINT x$;: WRITE x$: DATA "

Original versions (76 bytes golfed, 110 formatted):

READ a$:q$=CHR$(34):?a$+q$+a$+q$:DATA"READ a$:q$=CHR$(34):?a$+q$+a$+q$:DATA"

or

READ a$: q$ = CHR$(34): PRINT a$ + q$ + a$ + q$: DATA "READ a$: q$ = CHR$(34): PRINT a$ + q$ + a$ + q$: DATA "

DLosc

Posted 2011-01-28T00:34:05.293

Reputation: 17 064

Note that this doesn't work with QBasic 1.1 for MS-DOS 6.2: the autoformatter can't be turned off. – Mark – 2015-02-27T07:58:48.560

@Mark Good point. I added a formatted version. – DLosc – 2015-02-28T22:21:58.787

6

Lua, 44 bytes

s="s=%qprint(s:format(s))"print(s:format(s))

Some other comical answers in Lua:

print(arg[0])

...so long as the file is named print(arg[0]) And...

Lua: quine.lua:1: function arguments expected near '.'

...so long as the file is named quine.lua

thenumbernine

Posted 2011-01-28T00:34:05.293

Reputation: 331

6

Mathematica, 68 bytes

Print[#<>ToString[#,InputForm]]&@"Print[#<>ToString[#,InputForm]]&@"

celtschk

Posted 2011-01-28T00:34:05.293

Reputation: 4 212

6

T-SQL 24

This statment reproduces itself in the EVENTINFO column of the output:

dbcc inputbuffer(@@spid)

Explanation:

  • dbcc inputbuffer() - Displays the last statement sent from the client with the specified process id to the current instance of Microsoft SQL Server
  • @@spid - Retrieves the current process id

tested with SQL Server 2008 R2 and 2012; probably working with other versions as well

Online demo: http://www.sqlfiddle.com/#!3/d41d8/2230

GolfWolf

Posted 2011-01-28T00:34:05.293

Reputation: 7 688

6

Vitsy, 11 9 8 6 Bytes

This programming language was obviously made past the date of release for this question, but I thought I'd post an answer so I can a) get more used to it and b) figure out what else needed to be implemented.

'rd3*Z

The explanation is as follows:

'rd3*Z
'           Start recording as a string.

(wraps around once, capturing all the items)

'           Stop recording as a string. We now have everything recorded but the original ".
 r          Reverse the stack
  b3*       This equates the number 39 = 13*3 (in ASCII, ')
     Z      Output the entire stack.

Addison Crump

Posted 2011-01-28T00:34:05.293

Reputation: 8 084

6

ಠ_ಠ, 6 bytes

ಠಠ

This used to work back when the interpreter was still buggy but that's fixed now. However, you can try it in the legacy version of the interpreter!

Mama Fun Roll

Posted 2011-01-28T00:34:05.293

Reputation: 6 535

2It seems that also works in the interpreter provided. Also, ಠ is 3 bytes in UTF-8 – Conor O'Brien – 2016-08-19T21:53:23.813

Your link is dead, and can you upload the language source to GitHub so that it can be added to TIO? – Pavel – 2017-01-30T04:28:47.773

http://codepen.io/molarmanful/pen/rxJmqx all the code happens to be there. – Mama Fun Roll – 2017-01-30T17:58:03.387

6

Julia, 37 bytes

x=:(print("x=:($x);eval(x)"));eval(x)

Now that I know a bit more Julia, I thought I'd revisit this... due to the way printf works in Julia, my previous approach is clearly unsuitable. Instead we make use of (the tip of the iceberg of) Julia's homoiconic features. We define a symbol (that is, a representation of Julia code) which prints the framework of the code, as well as the contents of the variable x (via interpolation) and store that symbol in x. Then we eval that symbol. Much better. :)

Martin Ender

Posted 2011-01-28T00:34:05.293

Reputation: 162 549

6

beeswax, 17 13 bytes

Non-competing answer, beeswax is from 2015.

According to the discussion on Does using SMBF count as a cheating quine? the original version at the bottom would count as a cheating quine, so I am wondering if a small change would make this a “proper” quine. The new version is 4 bytes smaller and does not modify its own source code:

`_4~++~+.}1fJ

Explanation:

                lstack     STDOUT

 _             α[0,0,0]•                 create bees α,β, moving right and left
               β[0,0,0]•

` 4            α[0,0,4]•                 push 4 on top of α lstack, switch β to print mode
β α            β[0,0,0]•                 switch β to character output mode

   ~           α[0,4,0]•                 flip α lstack top and 2nd
    +          α[0,4,4]•                 lstack top = top+2nd
     +         α[0,4,8]•                 lstack top = top+2nd
      ~        α[0,8,4]•                 flip lstack top and 2nd
       +       α[0,8,12]•                lstack top = top+2nd
        .      α[0,8,96]•                lstack top = top*2nd
         }     α[0,8,96]•    ` ASCII(96) output char(lstack top) to STDOUT
          1    α[0,8,1]•                 lstack top = 1
           F   α[1,1,1]•                 all lstack = top
            J  α[1,1,1]•                 jump to (x,y) = (lstack top, lstack 2nd)
`_4~++~+.}1FJ  α[1,1,1]•   _4~++~+.}1FJ  output characters to STDOUT

This version should qualify as proper quine if the Befunge-93 program on Thompson’s Quine Page is listed as proper quine. The Befunge quine below does nothing else than read itself character by character, one character during each implicit loop, and output the character to STDOUT.

:0g,:93+`#@_1+

Correct me if I’m wrong.


Old (cheating?) version.

beeswax is a new 2D esolang on a hexagonal grid. It is inspired by bees, honeycombs and by the Hive board game (which uses hexagonal gaming pieces). beeswax programs are able to modify their own code. Thanks to this ability it is not too hard to create a quine. But the program does not read its own source code, as my explanation shows.

The first beeswax quine in existence:

_4~++~+.@1~0@D@1J

Or equivalently:

*4~++~+.@1~0@D@1J

IPs are called bees, the program area is called honeycomb. Every bee owns a local stack called lstack, carrying 3 unsigned 64 bit integer values.

Explanation:

                                             lstack
                                     • marks top of stack

* or _  create bee(same result in this situation)[0,0,0]•
 4      1st lstack value=4                       [0,0,4]•
  ~        flip 1st/2nd lstack values            [0,4,0]•
   ++      1st=1st+2nd, twice                    [0,4,8]•
     ~                                           [0,8,4]•
      +                                          [0,8,12]•
       .         1st=1st*2nd                     [0,8,96]•
        @  flip 1st/3rd lstack values            [96,8,0]• 
         1     1st=1                             [96,8,1]•
          ~                                      [96,1,8]•
           0   1st=0                             [96,1,0]•
            @                                    [0,1,96]•
             D drop 1st at row=2nd,col.=3rd val. [0,1,96]•
       This drops ASCII(96)= ` beyond the left border.

Dropping a value at a coordinate outside the program—in this case at column 0—grows the honeycomb by 1 column to the left. The coordinate system gets reset, so this column becomes the new column 1. So, growing the honeycomb in ‘negative’ direction is only possible in steps of 1. The grown honeycomb is always a rectangle encompassing all code.

This modifies the program to:

`*4~++~+.@1~0@D@1J

continuing...

               @                                  [96,1,0]•
                1                                 [96,1,1]•
                 J jump to row=1st,column=2nd val.[96,1,1]•
`                  switch to character output mode.
 *4~++~+.@1~0@D@1J    the following characters are printed to STDOUT.

GitHub repository of the Julia package of the beeswax interpreter.

M L

Posted 2011-01-28T00:34:05.293

Reputation: 2 445

6

Brainfuck, 392 bytes

Like this 755B answer, this quine is accompanied by an additional character, which appears in both source and output. I tested this using BFO in the windows terminal emulator ConEMU.

->++>+++>+>+>+++>>>>>>>>>>>>>>>>>>>>+>+>++>+++>++>>+++>+>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>+>+>>+++>>+++>>>>>+++>+>>>>>>>>>++>+++>+++>+>>+++>>>+++>+>++>+++>>>+>+>++>+++>+>+>>+++>>>>>>>+>+>>>+>+>++>+++>+++>+>>+++>>>+++>+>++>+++>++>>+>+>++>+++>+>+>>+++>>>>>+++>+>>>>>++>+++>+++>+>>+++>>>+++>+>+++>+>>+++>>+++>>++[[>>+[>]++>++[<]<-]>+[>]<+<+++[<]<+]>+[>]++++>++[[<++++++++++++++++>-]<+++++++++.<]\x1a

The source and output have no linebreaks. The last character is a \x1a (SUB ctrl code).

Invented by Daniel B Cristofani.

mınxomaτ

Posted 2011-01-28T00:34:05.293

Reputation: 6 642

The output is ASCII-only and has 392 bytes. The last byte, \x1a, is rendered as a right arrow in code page 437; it's not the same as the unicode right arrow \u2192. – Mitch Schwartz – 2016-01-03T20:20:00.367

(Put another way, the 394-byte program ending with \xe2\x86\x92 is not a quine, but it prints the 392-byte quine ending with \x1a.) – Mitch Schwartz – 2016-01-03T20:38:56.747

1If you haven't written this yourself, I think it should be community wiki. – Martin Ender – 2016-01-04T15:29:40.473

6

APL, 22 bytes

1⌽22⍴11⍴'''1⌽22⍴11⍴'''

This is part of the FinnAPL Idiom Library.

        '''1⌽22⍴11⍴'''  ⍝ The string literal '1⌽22⍴11⍴' (quotes in string)
     11⍴                ⍝ Fill an 11-element array with these characters
                        ⍝ But the string has length 10, so we get '1⌽22⍴11⍴''
  22⍴                   ⍝ Do this again for 22 chars: '1⌽22⍴11⍴'''1⌽22⍴11⍴''
1⌽                      ⍝ Rotate left (puts quote at the back)

Try it on ngn/apl

Alex A.

Posted 2011-01-28T00:34:05.293

Reputation: 22 170

6

Jolf, 4 bytes

Q«Q«
Q    double (string)
 «   begin matched string
  Q« capture that

This transpiles to square(`Q«`) (I accidentally did string doubling in the square function), which evaluates to Q«Q«. Note that q is the quining function in Jolf, not Q ;).

Conor O'Brien

Posted 2011-01-28T00:34:05.293

Reputation: 25 859

6

RETURN, 18 bytes

"34¤¤,,,,"34¤¤,,,,

Try it here.

First RETURN program on PPCG ever! RETURN is a language that tries to improve DUP by using nested stacks.

Explanation

"34¤¤,,,,"         Push this string to the stack
          34       Push charcode of " to the stack
            ¤¤     Duplicate top 2 items
              ,,,, Output all 4 stack items from top to bottom

Mama Fun Roll

Posted 2011-01-28T00:34:05.293

Reputation: 6 535

6

Fuzzy Octo Guacamole, 4 bytes

_UNK

I am not kidding. Due to a suggestion by @ConorO'Brien, K prints _UNK. The _UN does nothing really, but actually sets the temp var to 0, pushes 0, and pushes None.

The K prints "_UNK", and that is our quine.

Riker

Posted 2011-01-28T00:34:05.293

Reputation: 5 743

I was bored today and decided to quine in FOG. Couldn't figure it out, this is very clever – Bald Bantha – 2016-06-26T19:43:22.123

6

F#, 90 bytes

let q="let q=%A
printf(Printf.TextWriterFormat<_>q)q"
printf(Printf.TextWriterFormat<_>q)q

F#’s smart printf comes back to byte us! We can’t write let q="...";;printf q q, as the first parameter to printf isn’t actually a string:

printf : TextWriterFormat<'T> -> 'T

F# uses some compiler magic under the hood to guarantee type-safe printf calls. For example, "yay %d wow!" is a valid TextWriterFormat<int -> unit> literal, but not a valid TextWriterFormat<double -> unit> literal. But if we define the format string separately, the compiler will see it as a regular old string and complain. Instead, we have to convert q ourselves in the first argument.

What about let q:TextWriterFormat<_>="..."? First of all, that’s two bytes longer. But second of all, the second argument to printf really needs to be a string, otherwise the typechecker will infer that we’re formatting a formatter, which in turn formats a formatter, which formats a…

error FS0001: Type mismatch. Expecting a
    'a    
but given a
    Printf.TextWriterFormat<('a -> unit)>    
The resulting type would be infinite when unifying ''a' and
    'Printf.TextWriterFormat<('a -> unit)>'

Yep, an infinite type. Oops.

Lynn

Posted 2011-01-28T00:34:05.293

Reputation: 41 980

+1 for emoticon in the code &lt;_&gt; – user48538 – 2016-08-03T18:32:49.233

6

C++, 286 284 236 bytes

Now with extra golf!

#include<iostream>
int main(){char a[]="#include<iostream>%sint main(){char a[]=%s%s%s,b[]=%s%s%s%s,c[]=%s%sn%s,d[]=%s%s%s%s;printf(a,c,b,a,b,b,d,b,b,b,d,b,b,d,d,b);}",b[]="\"",c[]="\n",d[]="\\";printf(a,c,b,a,b,b,d,b,b,b,d,b,b,d,d,b);}

I'm currently learning C++, and thought "Hey, I should make a quine in it to see how much I know!" 40 minutes later, I have this, a full 64 114 bytes shorter than the current one. I compiled it as:

g++ quine.cpp

Output and running:

C:\Users\Conor O'Brien\Documents\Programming\cpp
λ g++ quine.cpp & a
#include<iostream>
int main(){char a[]="#include<iostream>%sint main(){char a[]=%s%s%s,b[]=%s%s%s%s,c[]=%s%sn%s,d[]=%s%s%s%s;printf(a,c,b,a,b,b,d,b,b,b,d,b,b,d,d,b);}",b[]="\"",c[]="\n",d[]="\\";printf(a,c,b,a,b,b,d,b,b,b,d,b,b,d,d,b);}

Conor O'Brien

Posted 2011-01-28T00:34:05.293

Reputation: 25 859

6

Cheddar, 56 bytes

var a='var a=%s;print a%@"39+a+@"39';print a%@"39+a+@"39

Try it online!

I felt like trying to make something in Cheddar today, and this is what appeared...

ETHproductions

Posted 2011-01-28T00:34:05.293

Reputation: 42 391

6

05AB1E, 19 bytes

Thanks to @Oliver for a correction (trailing newline)

"D34ç.øsJ"D34ç.øsJ

There is a trailing newline.

Try it online!

"D34ç.øsJ"             Push this string
          D            Duplicate
           34          Push 34 (ASCII for double quote mark)
             ç         Convert to char
              .ø       Surround the string with quotes
                s      Swap
                 J     Join. Implicitly display

Luis Mendo

Posted 2011-01-28T00:34:05.293

Reputation: 68 100

6

05AB1E, 16 17 bytes

"34çs«DJ"34çs«DJ

With trailing newline.

Try it online!

Explanation:

"34çs«DJ"        # push string
         34ç     # push "
            s«   # swap and concatenate
              DJ # duplicate and concatenate

acrolith

Posted 2011-01-28T00:34:05.293

Reputation: 3 040

5

C++ (350)

#include<iostream>
#include<fstream>
int main(){std::ofstream f;f.open("f.cpp");
#define B(x)x;f<<("B(" #x ")");
#define A(x)f<<("A(" #x ")");x;
B(f<<("#include<iostream>\n#include<fstream>\nint main(){std::ofstream f;f.open(\"f.cpp\");\n#define B(x)x;f<<(\"B(\" #x \")\");\n#define A(x)f<<(\"A(\" #x \")\");x;\n"))A(f<<("f.close();}\n"))f.close();}

Modified version of this.

Makes use of the C++ preprocessor.

Mateen Ulhaq

Posted 2011-01-28T00:34:05.293

Reputation: 1 093

4

tinylisp, 88 bytes

The byte count includes a trailing newline.

((q (g (c (c (q q) g) (c (c (q q) g) ())))) (q (g (c (c (q q) g) (c (c (q q) g) ())))))

Try it online!

There are no strings in tinylisp, but a nontrivial quine is still possible because code is lists and lists are code. The above code is a list which, when evaluated, returns (and therefore prints) itself.

The idea is to pass the list (g (c (c (q q) g) (c (c (q q) g) ()))) to a function which will wrap it in a list, tack a q on the front, and then wrap two copies of that in a list. Which is exactly what the function (q (g (c (c (q q) g) (c (c (q q) g) ())))) does. In-depth explanation available on request, but I wanted to post this before turning in for the night.

DLosc

Posted 2011-01-28T00:34:05.293

Reputation: 17 064

4

Befunge-98 (cfunge), 8 characters

 'k<@,k␇

represents a literal BEL character (ASCII 7, or Ctrl-G). (Note also that the program starts with a leading space.)

Note that the k command, which is heavily used here, is somewhat imprecisely defined, and this code is outright exploiting several edge cases at once, making this an example of corner-case code. As such, this is somewhat interpreter-dependent; it doesn't work on TIO, for example. cfunge is the Befunge-98 interpreter I normally use locally (and has been tested to be highly conformant with the specification), and it handles this code correctly. (Update: I've been talking to some Befunge experts about this quine, and the consensus is that it's exploiting a bug in cfunge, not behaviour that's defensible by the specification. Still a valid answer, though, because languages are defined by their implementation and this is the sort of corner case that has no right answers, only wrong answers.)

This program would also work in Unefunge-98 and Trefunge-98, but I'm not sure if any of the pre-existing interpreters for those handle k in the way we need, so it may be noncompeting in those languages.

Verification

$ xxd /tmp/quine.b98
00000000: 2027 6b3c 402c 6b07                       'k<@,k.
$ ./cfunge /tmp/quine.b98 | xxd
00000000: 2027 6b3c 402c 6b07                       'k<@,k.

Explanation

General principles

We know that in fungeoids, it's normally easiest to wrap a string around the code, so that the code is inside and outside the string literal at the same time. However, another trick for shortening quines is to use a string representation which doesn't need escaping, so that we don't need to spend bytes to represent the string delimiter itself. So I decided to see if these techniques could be combined.

Befunge-98 normally uses " as a string delimiter. However, you can also capture a single character using ', and you can make any command into a sort of lightweight loop (in a confusing and buggy way) using k. As such, k' functions as a sort of makeshift length-prefixed string literal. And of course, a length-prefixed string literal has no problems in escaping its own delimiter, as it doesn't have any sort of string terminator at all, meaning that the entire range of octets (in fact, the entire range of cell values) are available to exist within the string.

We can actually do even better; we no longer have to stop the string at its opening delimiter (we can stop it anywhere), so we can wrap it multiple times around the program to grab not only the k' itself, but also the length of the string (which is in this case written as a character code, thus the literal backspace). The program will continue execution just after the end of the string, i.e. just after the last character captured, which is exactly where we want it. (Bear in mind that Befunge strings are printed in reverse order to pushing them; the most common form, NUL-terminated strings, are called "0gnirts" by the community because of this, and length-prefixed strings follow the same principle. Thus if we want the length to end up at the start of the string, we have to push it last.)

As an extra bonus, this also means that we can wrap multiple times around the program with no penalty; all that matters is that the last character we see is the string length (which is at the end of the program). By an amazing stroke of luck, k' specifies length-prefixed string (sort-of; k is weird), and 'k (the same two characters in reverse order) pushes 107, which happens to loop round the program multiple times and end up in exactly the right place (this only had a 1 in 8 chance of working out). Because we have to reverse the program direction anyway (to read the string in the reverse of the natural reading order, meaning that it gets printed in the same order it appeared in the original program), we can use the same two characters for both pushing the length, and pushing the string itself, at no cost.

Of course, this now captures a risk of counting as a literal-only program, and thus not a proper quine under PPCG rules. Luckily, wrapping round from one end of the program to the other produces a literal space character, and spaces at the ends of the line (i.e. leading and trailing whitespace) aren't captured as part of a string. Thus, if we start the program with a space, we can encode that space (which isn't part of the string literal) via the implicit space that we get from wrapping the program (i.e. the leading space is encoded by the ' next to it, rather than by itself), just sneaking within the proper quine rules. The easiest way to see this is to delete the leading space from the program; you'll get the same output as the program with the leading space (thus effectively proving that it doesn't encode itself, because even if you remove it it still gets printed).

Detailed description

 'k<@,k␇
 'k       Push 107 to the stack
   <      Set execution delta to leftwards
 'k       Push the next 107 characters to the stack: "'␠␇k, … @<ck'␠␇"
     ,k   Pop a length from the stack, output that many characters
     ,    Output the top stack element
    @     Exit the program

You can note that k has some odd ideas of where to start reading the string from (for the first k that runs), or where to leave the IP afterwards (for the second k that runs); this is just the way k happens to work (you think of k as taking an "argument", the command to run, but it doesn't actually move the IP to skip the "argument"; so if the command inside the loop doesn't affect the IP or the IP's movement, it'll end up being the next command that runs and the loop runs one more time). The literal BEL, ASCII 7, is interpreted by the second k as a loop counter, so the , inside the k will print the first 7 characters, then the , outside the k (which is the same character in the source) will print the 8th just before the program exits.

user62131

Posted 2011-01-28T00:34:05.293

Reputation:

4

///, 204 bytes

/<\>/<\\\\>\\\\\\//P1/<>/<<>\><>/<<>\<>\<>\<>\><>\<>\<>\<>\<>\<>\<>/<>/P<>1<>/P<>2<>/<>/P<<>\<>\><>\<>\<>2<>/P<>1<>/<>/<<>\><>/<<<>\<>\>><>\<>\<>/<>/<<>\<>\><>/<>/P<>1//P<\\>\\2/P1//<\>/<<\\>>\\//<\\>//P1

Try it online!

With some helpful whitespace inserted:

/<\>/<\\\\>\\\\\\/
/P1/
    <>/<<>\><>/<<>\<>\<>\<>\><>\<>\<>\<>\<>\<>\<>/<>/P<>1<>/P<>2<>/<>/P<<>\<>\><>\<>\<>2<>/P<>1<>/<>/<<>\><>/<<<>\<>\>><>\<>\<>/<>/<<>\<>\><>/<>/P<>1
/
/P<\\>\\2/P1/
/<\>/<<\\>>\\/
/<\\>//
P1

How it works

  • The long third line is the quining data. It is made from the entire rest of the program, with a P2 in the spot where the data itself would fit, and then with the string <> inserted before each character from the set \/12.
    • It would be harmless to put <> before all characters in the data, but only these are necessary - \/ because they need escaping to be copied, and 12 because it's vital to have a break inside P1 and P2 to prevent infinite loops when substituting them.
  • The first substitution changes all the <> prefixes into <\\>\\\. The \ in the source <\> is there to prevent its final printable form from being garbled by the other substitutions.
  • The second substitution includes the quining data, copying them to the other P1s in the program. The <\\>\\\ prefixes now become <\>\ in both copies.
  • The third substitution copies one of the quining data copies (in the substitution itself) into the middle of the other (at the end of the program), marked by the string P<\>\2. In the inner copy, the <\>\ prefix now becomes <> again.
  • The fourth substitution changes the inner copy's <> prefixes into <<\>>\. The change is needed to introduce the final backspace, protecting any following \s and /s that are to be printed. The inner <\> is necessary to prevent this substitution from infinitely looping – just a backslash here wouldn't do, as it would be garbled by the fifth substitution.
  • The fifth substitution removes all instances of the string <\>, both those remaining in the outer copy of the quining data, and those produced by the fourth substitution.
  • Finally, we reach the constructed copy of the program, with suitable backslashes prepended to some characters, ready for printing.

Ørjan Johansen

Posted 2011-01-28T00:34:05.293

Reputation: 4 894

4

Alice, 45 bytes

Credit to Martin Ender for the use of %, r, and y to obtain the characters "/\ without escaping.

/?.!eO%?.*y1?@~mtz!!4\
\"Y!Z1hrZRoY@*m*h%1Y{/

Try it online!

This program runs entirely in ordinal mode. Because of how ordinal mode programs need to be formatted, this is significantly longer than Martin Ender's cardinal mode quine.

In ordinal mode, the instruction pointer moves diagonally, and commands work on strings instead of integers. The diagonal movement is what makes this tricky: there is even a challenge specifically about formatting a program for ordinal mode. While it's possible to sidestep the entire issue by putting the same string on both lines, this approach ends up slightly longer at 52 bytes.

\".!e1%r.Ryh?*.Ooo1m@z1!{
\".!e1%r.Ryh?*.Ooo1m@z1!{/

Try it online!

Explanation

This is a standard template for ordinal mode, with an additional mirror to allow the program to loop back to the beginning. Linearized, the code is as follows:

".!e1%r.RyY?*~*t%!Y4?Y!ZOh?Z*o1@@mmhz1!{

As with many Fungeoid quines, the " wraps around to itself and puts this entire program in a string literal. Since string mode treats mirrors as mirrors (instead of literals), the string that gets pushed is exactly the linearized code, excluding the ".

.!     Duplicate the string, and move the copy to tape
e1%    Split on "1", placing "@@mmhz" and "!{" on top of the stack.
       The other two parts are irrelevant.
r      Expand !{ into the entire range from code point 33 to 123.
.R     Duplicate and reverse this range
y      Modify the string @@mmhz by changing every character in the range 33-123 
       with the corresponding character in the reversed range.
       The result of this transformation is \\//4" .
       This allows us to get these characters without escaping them.
Y?*~*  Split this string in half by unzipping, and put the halves on either
       side of the original string.  The new string is \/"sourcecode\/4 .
t%     Extract the newly added 4 at the end, and use it to split on the single 4 in the code.

At this point, we have two strings corresponding to approximately half of the code. The top of the stack has the second half of the program and the right side mirrors, and corresponds to these output bytes:

 ? ! O ? * 1 @ m z ! \
  Y Z h Z o @ m h 1 {/

The string below that has the first half of the program, along with the left side mirrors and quote:

/ . e % . y ? ~ t !
\" ! 1 r R Y * * % Y

Neither string currently contains the 4 that was used to split the string.

!      Move second half string to the tape.
Y      Unzip first half: the top of the stack now contains the characters
       from the first half that will end up in the first row of the output.
4      Append the digit 4 to this string.
?Y     Copy second half back from tape and unzip: the top of the stack contains
       characters from the second half that will end up in the second row
!      Move this onto the tape.
Z      Zip the two halves of the first row together.
O      Output this with a linefeed.
h      Temporarily remove the initial \ so the next zip will work right.
?Z     Copy the string back from the tape, and zip the second row together.
       This Z isn't the exact inverse of Y since the second half is longer.
       The resulting behavior is exactly what we want.
*o     Join with the previously removed \ and output.
1      Append 1 to the irrelevant string on the top of the stack.
@      Terminate.

The 52-byte quine works on exactly the same principle, except that it doesn't need the ordinal formatting section of the 45-byte quine.

Nitrodon

Posted 2011-01-28T00:34:05.293

Reputation: 4 131

4

Taxi, 1144 1034 970 bytes

"is waiting at Writer's Depot.34 is waiting at Starchild Numerology.Go to Starchild Numerology:w 1 r 3 l 2 l 3 l 2 r.Pickup a passenger going to Charboil Grill.Go to Charboil Grill:e 1 l.Pickup a passenger going to KonKat's.Go to Writer's Depot:w 1 r.Pickup a passenger going to KonKat's.Go to KonKat's:n 3 r 2 r.Pickup a passenger going to Cyclone.Go to Cyclone:n 1 l 2 l.Pickup a passenger going to Post Office.Pickup a passenger going to Post Office.Go to Post Office:s 1 l 2 r 1 l."is waiting at Writer's Depot.34 is waiting at Starchild Numerology.Go to Starchild Numerology:w 1 r 3 l 2 l 3 l 2 r.Pickup a passenger going to Charboil Grill.Go to Charboil Grill:e 1 l.Pickup a passenger going to KonKat's.Go to Writer's Depot:w 1 r.Pickup a passenger going to KonKat's.Go to KonKat's:n 3 r 2 r.Pickup a passenger going to Cyclone.Go to Cyclone:n 1 l 2 l.Pickup a passenger going to Post Office.Pickup a passenger going to Post Office.Go to Post Office:s 1 l 2 r 1 l.

Please ignore the output to stderr. Who needs a job if you can quine anyway?

Try it online!

How does this work?

Short answer

This quine starts with a string. If you replace the content of that string by <string>, the code looks like "<string>"<string>, which is "<string> twice. Because the string doesn't contain the double quote, we first get the double quote via its character code, concatenate it with the string, then copy the string and concatenate it with itself. Finally, we print the string.

Long answer

under construction

Luke

Posted 2011-01-28T00:34:05.293

Reputation: 4 365

4

Brain-Flak, 1993 + 3 = 1996 bytes

(())(()()()())(())(())(()()())(())(())(())(()()()())(())(())(()()()())(())(()()())(()())(()()())(())(()()()())(())(())(())(())(())(()())(()()()())(()())(()()())(())(()()())(()())(())(()()())(())(())(()()()())(())(())(()()()())(())(()()())(()())(()()())(())(()()()())(())(())(())(()()())(()()()())(()())(()()())(())(())(()()())(())(())(())(())(()()()())(())(())(()()()())(())(()()())(()())(()()())(())(()()()())(())(())(())(())(())(())(()()())(())(())(()()()())(())(())(()()()())(())(()()())(()())(()()())(())(()()()())(()()()())(())(())(())(())(()()())(()()()())(()())(())(()())(()()())(())(()())(())(()()())(()())(()()()())(()())(())(())(()()())(())(())(())(()()())(()()())(()()()())(())(()()())(()())(()())(())(()()())(())(())(())(())(()()())(()()()())(())(()())(())(()()())(()())(()()())(())(())(())(())(())(())(()())(())(()())(())(()())(())(())(()()())(()())(())(())(())(())(()()()())(()())(())(())(()()())(()())(())(()()())(())(()()())(()())(())(())(()()())(())(())(()())(())(()())(())(()())(())(()())(())(()())(()())(()())(())(())(())(()())(())(())(()()())(()())(()())(()()()()())(()())(()())(()()()())(())(())(()()())(()())(()())(())(()()()())(()()()())(())(())(()())(())(()()())(()())(()())(()()()())(())(())(()())(()()()()())(()()())(())(()())(()())(())(())(()())(())(()()())(())(())(())(()()()())(())(())(())(())(()())(()()()()())(())(())(()())(())(()()())(()())(()())(()())(())(()()()())(())(())(()())(())(()()())(()())(()()()())(()()())(())(())(())(()()())(()()()()())(()())(()())(())(()()()())(())(())(())(()())(()()()()())(())(())(()())(())(()()())(())(())(()()())(())(())(()()())(())(())(()())(())(()())(())(()())(())(()())(())(()())(()())(()())(()())(()())(()())(())(()()()())(()()()){<>(((((()()()()()){}){}){}())[()])<>(([{}]){<({}())<>((({}())[()]))<>>}{}())((){[()]<(({}())<<>(({})<(([(({})())]((()()()()()){})({}{}({})(<>)))({})()()())>)>){({}()<{}>)}{}(({}<{{}}>{})(<({}(){()(<{}>)}<<>{({}<>)<>}{}>)>))<>{({}<>)<>}>}{}){(<{}>)<>{({}<>)<>}{}({}{(<()>)})<>{({}<>)<>}}{}}<>

Try it online!

Like Funky Computer Man's answer, I encode every closing bracket as 1. The assignment of numbers to the four opening brackets is chosen to minimize the total length of the quine:

2: ( - 66 instances
3: { - 45 instances
4: < - 30 instances
5: [ -  5 instances

The other major improvement over the old version is a shorter way to create the code points for the various bracket types.

The decoder builds the entire quine on the second stack, from the middle outward. Closing brackets that have yet to be used are stored below a 0 on the second stack. Here is a full explanation of the decoder:

# For each number n from the encoder:
{

 # Push () on second stack (with the opening bracket on top)
 <>(((((()()()()()){}){}){}())[()])<>

 # Store -n for later
 (([{}])

  # n times
  {<({}())

    # Replace ( with (()
    <>((({}())[()]))<>

  >}{}

  # Add 1 to -n
  ())

  # If n was not 1:
  ((){[()]<

     # Add 1 to 1-n
     (({}())<

       # Using existing 40, push 0, 91, 60, 123, and 40 in that order on first stack
       <>(({})<(([(({})())]((()()()()()){})({}{}({})(<>)))({})()()())>)

     # Push 2-n again
     >)

     # Pop n-2 entries from stack
     {({}()<{}>)}{}

     # Get opening bracket and clear remaining generated brackets
     (({}<{{}}>{})

      (<

        # Add 1 if n was 2; add 2 otherwise
        # This gives us the closing bracket
        ({}(){()(<{}>)}

         # Move second stack (down to the 0) to first stack temporarily and remove the zero
         <<>{({}<>)<>}{}>

        # Push closing bracket
        )

      # Push 0
      >)

     # Push opening bracket
     )

     # Move values back to second stack
     <>{({}<>)<>}

   # Else (i.e., if n = 1):
   >}{})

 {

  # Create temporary zero on first stack
  (<{}>)

  # Move second stack over
  <>{({}<>)<>}

  # Move 0 down one spot
  # If this would put 0 at the very bottom, just remove it
  {}({}{(<()>)})

  # Move second stack values back
  <>{({}<>)<>}}{}

}

# Move to second stack for output
<>

Nitrodon

Posted 2011-01-28T00:34:05.293

Reputation: 4 131

It looks like you have a stray newline at the end of your code. You can save a byte by removing it. – 0 ' – 2017-12-28T18:55:44.147

@0 ' Since Brain-Flak prints with a trailing newline. It is necessary for it to be a quine – H.PWiz – 2018-01-19T18:32:06.677

4

JavaScript, 53 bytes

A quine without any uses of uneval or Function.prototype.toString.

Q="q=Q.link()[8];alert(`Q=${q+Q+q};eval(Q)`)";eval(Q)

Can avoid use of template strings for + 1 byte.

Q="q=Q.link()[8];alert('Q='+q+Q+q+';eval(Q)')";eval(Q)


JavaScript, 74 bytes

Another approach avoiding uneval and Function.prototype.toString:

console.log(a="console.log(a=%s%s%s,q=a.link()[8],a,q)",q=a.link()[8],a,q)

Dom Hastings

Posted 2011-01-28T00:34:05.293

Reputation: 12 968

4

Bash, 48 bytes

Q=\';q='echo "Q=\\$Q;q=$Q$q$Q;eval \$q"';eval $q

Try it online!

Dom Hastings

Posted 2011-01-28T00:34:05.293

Reputation: 12 968

1Hm the leaderboard gives a shorter one, although that one uses sed while you are only using builtins. – Ørjan Johansen – 2018-02-07T17:14:14.463

After a search, I think this is currently the shortest with only builtins and a "normal" quine construction. – Ørjan Johansen – 2018-02-07T17:28:39.610

Thanks for taking a look @ØrjanJohansen! I'd like to differentiate this from the other solutions, but I don't know if I should change this title or the ones that use core utils... I'm happy with just coming up with the program to be honest! – Dom Hastings – 2018-02-07T19:22:53.660

Bash + coreutils seems to be fairly common, so I'd suggest to edit the header of the other answer. – Laikoni – 2018-02-10T12:07:26.533

4

CSS, 47 bytes

<style>:before,*{display:block;content:'<style>

Paste into a blank HTML page to avoid conflict with other tags.

Mama Fun Roll

Posted 2011-01-28T00:34:05.293

Reputation: 6 535

Wouldn't this technically be HTML with embedded CSS in it? Also, what browser did this successfully quine in, because when I test this with an empty HTML file, it displays :before,*{display:block;content:'&lt;style&gt; on the window. – Patrick Roberts – 2017-07-16T05:08:27.367

4

Arcyóu, 1 byte

Q

The interpreter evaluates undefined symbols as strings, and the result of the last expression evaluated is automatically printed at the end of the program. What's interesting is that any undefined identifier can be used; I_am_a_quine! is also a quine.

bkul

Posted 2011-01-28T00:34:05.293

Reputation: 1 452

This does not satisfy our rules for proper quines as the Q only encodes itself (as does any character in I_am_a_quine!).

– Martin Ender – 2017-05-23T15:35:41.030

Agreed @MartinEnder, but the challenge does not specify proper quines. – bkul – 2017-06-02T21:30:24.970

4

Bash + coreutils, 18 bytes

sed p<<a
sed p<<a

It requires a trailing newline and generates a warning.

Posted the Zsh version in a separate answer to fix the leaderboard.

jimmy23013

Posted 2011-01-28T00:34:05.293

Reputation: 25 688

Interesting use of the here-document, but one has to end the text stream manually with Ctrl+D to make the script run, hence the warning. To have it run automatically, an extra line with just a on it is required, but that would break the quine. – seshoumara – 2016-09-07T08:53:14.830

@seshoumara Just put it in a script file and use bash filename to run. – jimmy23013 – 2016-09-07T09:22:31.833

Aah, you give an EOF this way, nice. Maybe add that to description. I run it with bash script 2&gt; /dev/null to get rid of STDERR. – seshoumara – 2016-09-07T09:31:29.967

In dash and zsh, you don't need the trailing newline and it won't generate a warning. – Dennis – 2016-09-08T15:49:25.540

1@seshoumara Answers on this site should be functions or complete programs, and not code snippets in a REPL, by default. – jimmy23013 – 2016-09-08T21:12:45.130

4

JavaScript, 58 54 bytes

I present to you the shortest non-source-reading quine in JavaScript:

console.log(a="console.log(a=%s,uneval(a))",uneval(a))

How have I not thought of this before? Screw that, how has nobody thought of this before? :P

Here's a version that works in all browsers at the cost of 9 bytes:

q='"';console.log(a="q='%s';console.log(a=%s,q,q+a+q)",q,q+a+q)

ETHproductions

Posted 2011-01-28T00:34:05.293

Reputation: 42 391

If this works in the browser, you can make console.log be alert. – Conor O'Brien – 2016-09-07T01:56:36.643

1@ConorO'Brien Nope. The %s in the string only works with console.log. – ETHproductions – 2016-09-07T02:00:58.587

ahhh that's what that was. – Conor O'Brien – 2016-09-07T11:02:28.157

Lolp I was trying to do that a while ago, I couldn't figure out string formatting – Oliver Ni – 2016-10-23T05:26:57.943

3

BotEngine, 4x1=4 bytes

TRUE

The T instruction deletes the active bot and prints TRUE.

SuperJedi224

Posted 2011-01-28T00:34:05.293

Reputation: 9 433

3

Malbolge, 59851 Bytes, Non-competing.

I take no credit for this quine, all credit goes to this person

Newlines are significant, Compressed into a code snippet because otherwise this wouldn't fit.

var byteArray = pako.inflate(atob('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'));
var byteString = "";
for (var i = 0; i < byteArray.length; i++) byteString += String.fromCharCode(byteArray[i]);
document.querySelector("code").textContent = decodeURIComponent(escape(byteString));
<script src="https://cdn.rawgit.com/nodeca/pako/master/dist/pako.min.js"></script>
<pre><code></code></pre>

ATaco

Posted 2011-01-28T00:34:05.293

Reputation: 6 373

Please note that Community Wiki is not a rep waiver so there is no real need for you to have marked it as such. – MD XF – 2017-06-14T02:54:01.130

Unless my clipboard is playing tricks on me, your snippet shows only 46485 characters. – Dennis – 2017-06-25T22:29:35.807

@Dennis Snippet is compressed – ATaco – 2017-06-25T22:30:59.133

Yes. I copied the output of the Stack Snippet. Copy-pasting from the original website works fine btw. – Dennis – 2017-06-25T22:32:01.120

The problem is most likely because of whitespace and/or HTML escapes. .html won't work properly for a div. – Dennis – 2017-06-25T22:37:16.787

@Dennis probably I'll look into it when I get to a computer – ATaco – 2017-06-25T22:38:02.670

Took the liberty to make the output copy-pastable. According to the result on TIO, you need to count a trailing newline though. – Dennis – 2017-06-25T22:56:03.783

3

Haystack, 7 bytes

Yay, my first quine!

"34c,o|

Try it online!

Explanation

This is a standard 2D quine.

"           starts to push a string
34c,o|      part of the string
"           it wraps around and go to the beginning of this line thus pushing the string
34          push this number
c           output as character (ie outputs ")
,           discard this value
o           output the top of stack (ie 34c,o|)
|           end program

Cows quack

Posted 2011-01-28T00:34:05.293

Reputation: 12 883

3

Actually, 4 bytes

0
0

Note the trailing linefeed. Try it online!

This exploits a potential flaw in our definition of proper quine:

It must be possible to identify a section of the program which encodes a different part of the program. ("Different" meaning that the two parts appear in different positions.)

Furthermore, a quine must not access its own source, directly or indirectly.

The stack of Actually is printed backwards, so the first 0 encodes the second 0, and vice versa.

This can be verified empirically; the program

1
2

prints

2
1

Try it online!

Dennis

Posted 2011-01-28T00:34:05.293

Reputation: 171 923

3

Logicode, 1368 1241 1096 1086 bytes

var a=000101011000111101001111001011000110100000111000001010001100101010100101011010111110110001111011111101110110010001000001100101010110101111101000000010100011001010111100010101111001010111110011110001010111100101011111001111100111100010101111001010111110011111001111100111100010101111001010111110011111001111100111110011110001010111100101011111001111100111110011111001111100111100010101111001010111110011111001111100111110011111001111100111100010100101010111110000010100011001010111110011111001111100111110011111001111100111110010100101011111100101000101011011111110101111010001000001110000010100001100010110001011000101100000110001011000101100000110001011000101100000110000011000001100000110001011000101100010110001011000001100000110001011000001100000110001011000001100000110000011000001100000110001011000101100000110000011000001100000110001011000001100010110001011000101100010110000011000101010010101011110000101010111110000010100011000010101001
circ p(e)->cond e->@(e<+e><+e>><+e>>><+e>>>><+e>>>>><+e>>>>>><)+p(e>>>>>>>)/e
out p(111011011000011110010010000011000010111101)+a+p(a)

Try it online

Explanation

This is pretty simple as far as Quines go. The first line of the program assigns a very long list of ones and zeros to a variable called a this is the binary representation of the last two lines of the program with each character represented by 7 bits.

Then I define a function that takes in a binary string and returns it as a ASCII string.

This works pretty simply:

circ p(e)->                                  #Function header
cond e->                                     #If e is non empty
@(e<+e><+e>><+e>>><+e>>>><+e>>>>><+e>>>>>><) #return the ASCII character made by the first 7 bit
+                                            #plus
p(e>>>>>>>)                                  #p of the rest of the string
/                                            #otherwise
e                                            #return e (i.e. the empty string)

Then on the last line we print var a= the binary string and the ASCII representation of the binary string.

Wheat Wizard

Posted 2011-01-28T00:34:05.293

Reputation: 33 549

3

Threead, 24 bytes

">34co<o>o<o">34co<o>o<o

Try it online!

I didn't think to do it like this until I saw Riley's answer. I have no intention to self-award the bounty, so this is non-competitive for it.

Explanation

">34co<o>o<o">34co<o>o<o
">34co<o>o<o"               # Encodes the right half of the program as a string, in the 1st buffer.
             >              # Move to the 2nd buffer.
              34c           # Put the string represented by ascii 34 (") in the second buffer.
                 o          # Write it to STDOUT
                  <o        # Move to the 1st buffer, Write the contents of the string to STDOUT.
                    >o      # Move back to the 2nd Buffer, write it.
                      <o    # Move back to the 1st Buffer, write it.

Originally... 129 Bytes...

My plan was to use:

"\x0E\x0E\x0E78g\x0EBv$/s@$@c8$$$$$vB\x0Ep$/c6Bb_$f$vgs@$/Bba\x0E$$$c5$$$$$1c5$$$$p"

34c
>r +o< <_4     r>
l +_2>^[ b rco< +>^]
   _1     -_1    l

where \x0E is the literal SOH.

Try it online!

The string is simply all the commands after it, but with a byte value 4 higher. This was because I can't store a " or a \ in the string, without it getting meta. The rest of the script, acts kind of like my other solution, however manually iterates through the string, printing each character -4.

ATaco

Posted 2011-01-28T00:34:05.293

Reputation: 6 373

2"I have no intention to self-award the bounty." You can't. – Martin Ender – 2017-01-13T09:10:43.183

4The README on github doesn't seem to mention that you can push string literals. – Riley – 2017-01-13T14:58:08.177

@Riley True, but you can figure that out by looking at the Threead "Hello, World!" program. – mbomb007 – 2017-01-13T21:56:01.230

Question, how does string multiplication work? I was trying to get it to work on TIO (to solve your bounty), and I couldn't figure it out. – mbomb007 – 2017-01-13T22:00:46.580

1

@mbomb007 Hopefully this will help you out. And Riley sorry about that, the readme was kind of poorly written.

– ATaco – 2017-01-14T04:41:28.710

3

C++, 117 bytes

#include<cstdio>
#define Q(S)char*q=#S;S
Q(int main(){printf("#include<cstdio>\n#define Q(S)char*q=#S;S\nQ(%s)",q);})

Ralph Tandetzky

Posted 2011-01-28T00:34:05.293

Reputation: 175

1What compiler does this use? This does not appear to work on gcc. – Wheat Wizard – 2017-01-13T15:26:59.500

It works on my gcc 4.9.2. – Ralph Tandetzky – 2017-01-13T15:38:22.537

1Ok. According to clang, this is not valid C++, since the return type of main() is missing. I fixed that now. – Ralph Tandetzky – 2017-01-13T15:40:40.627

My version of gcc was 4.2.1 (I should update some time). Now that main has a return type it works. – Wheat Wizard – 2017-01-13T15:47:41.360

3

Befunge-93, 17 bytes

Thanks to James Holderness for pointing out that this relies on nonstandard interpreter behavior

Slightly late to the party, but here goes!

<@,*2+98_,#! #:<"

Try it here, but you have to copy-paste the code. The program relies on nonstandard interpreter behavior, so it'll print a bunch of leading spaces on TIO. Oops. My bad.

<: sets the program direction to "left"; instruction pointer wraps around

": toggles string mode (pushes ascii value of every character until next ", which it encounters only when it wraps around)

(at this point, it pushes every character to the stack & wraps around. This is where it relies on nonstandard behavior - TIO and the reference interpreter would push a bunch of spaces to the stack)

:<: sets the instruction pointer direction to "left" and duplicates top of stack

! #: negates the value at the top (important because of the upcoming _); # skips the next character

_,#: checks the value at the top of the stack & pops it: prints the ascii value as a character of the new top and sets the direction of the instruction pointer to right if checked character was 0; else sets the direction of the instruction pointer to left

@,*2+98: prints the " at the end of the program and quits.

osuka_

Posted 2011-01-28T00:34:05.293

Reputation: 346

3

Brachylog (2), 26 bytes, language postdates challenge

"ạ~bAh34∧A~ạj"ạ~bAh34∧A~ạj

Try it online!

A function that returns its own source code. (This can be made into a 28-byte full program by adding w after each occurrence of j.)

Explanation

"ạ~bAh34∧A~ạj"ạ~bAh34∧A~ạj
"ạ~bAh34∧A~ạj"               String literal
              ạ              Convert to list of character codes
               ~b            Prepend an element
                  h34          so that the first element is 34
                 A   ∧A        but work with the entire list
                       ~ạ    Convert to string
                         j   Concatenate the string to itself

user62131

Posted 2011-01-28T00:34:05.293

Reputation:

3

Operation Flashpoint scripting language,  22  15 bytes

q={"q={"+q+"}"}

Call with:

hint call q

Output:

q={"q={"+q+"}"}

Old version (22 bytes):

q={format["q={%1}",q]}

Steadybox

Posted 2011-01-28T00:34:05.293

Reputation: 13 488

3

><>, 9 bytes

":1-or>o#

Try it online! Exits with an error. Since the top answer reads from its source code, I present this program.

":1-or>o#
"........   capture these characters
 :          duplicate last character (`#`)
  1-        decrement it (`"`)
    o       output it
     r      reverse the stack
      > #   loop inner
       o    output

The # is a very repulsive mirror--anything that touches it will go the other way. In this case, it is functionally the same as <.

Conor O'Brien

Posted 2011-01-28T00:34:05.293

Reputation: 25 859

2# is the same as #! – Christopher – 2017-05-21T12:30:36.217

@Christopher thanks – Conor O'Brien – 2017-05-21T12:44:40.353

No problem. I figured that something was up :P – Christopher – 2017-05-21T18:39:07.313

I like the trick of decrementing #. +1 – Esolanging Fruit – 2017-06-01T15:42:43.433

3

Klein, 11 + 6 = 17 bytes

Martin Ender has made another Quine here

+6 from the 000 topology and the -A flag, (also works in the 001 topology)

<3+@+3<"

Try it online!

Explanation

Like described in my earlier not so Quine the " character cannot be made with a string literal so we need to make it by doing math on a similar character, in this case the unit separator character for reasons described later. The difference between this Quine and earlier attempts is that this we can get around the restriction of having to read the string forwards by making the string itself a palindrome. This way reading backwards is the same as reading it forwards.

So when the program starts it passes through a unit separator, then hits < which turns it around, it goes through the " and pushes the entire line. :3+ turns makes a " out of the final unit separator and @ terminates the program causing it to print.

Wheat Wizard

Posted 2011-01-28T00:34:05.293

Reputation: 33 549

3

Groovy, 48 bytes

The language's pretty groovy too.

s="s=%c%s%c;printf(s,34,s,34)";printf(s,34,s,34)

Try it online!

totallyhuman

Posted 2011-01-28T00:34:05.293

Reputation: 13 394

3

Ruby, 26 bytes

eval s="$><<'eval s=';p s"

Try it online!

$><<'...' is equivalent to print'...' (outputs the string without a newline).

Nnnes

Posted 2011-01-28T00:34:05.293

Reputation: 355

Welcome to the site! Nice first answer :) – DJMcMayhem – 2017-06-12T17:07:23.263

3

Mathematica 17 19

ToString[#0][] & []

alephalpha

Posted 2011-01-28T00:34:05.293

Reputation: 18 628

Why Community Wiki? – MD XF – 2017-06-12T23:47:55.070

3

Octave, 28 bytes

Note: This doesn't work on TIO. I guess it's because TIO doesn't store the command history. It works on the desktop version. I tried it in Octave 4.2.1.


printf('%s',[history(1){:}])

So, what's going on here?

history is a function that can be used to read and manipulate the command history.

history(n) shows the n most recent commands you have typed, numbered:

>> x = 1 + 2;
>> y = x * 3;
>> history(3)
    7 x = 1 + 2;
    8 y = x * 3;
    9 history(3)

As you can see, x = 1 + 2 was the seventh command that was typed after the history was cleared the last time. The command history(3) is included in this list.

Now, history(1) is not a quine, since it gives:

>> history(1)
   10 history(1)

However, if you assign the output from history(1) to an output, you'll get:

>> x = history(1)
x =
{
  [1,1] = x = history(1)
}

It's still not a quine, but it's something we can work with.

Unwrapping this, and we're a bit closer:

>> [history(1){:}]
ans = [history(1){:}]

Notice that the entire command, including brackets are outputted.

Finally, if we print this as a string, using printf, we get:

>> printf('%s',[history(1){:}])
printf('%s',[history(1){:}])

Note: disp([history(1){:}]) almost works, but it appends a trailing newline.

Stewie Griffin

Posted 2011-01-28T00:34:05.293

Reputation: 24 204

Wouldn't disp([history(1){:}])\n work for 27 bytes? – caird coinheringaahing – 2017-08-29T14:47:18.000

3

><>, 8 bytes

#o<}-1:"

Try It Online

Copied the trick of copying and decrementing the # to get " from the other ><> answer, but uses both sides of the # to avoid needing to reverse the stack.

Edit: A much cleaner solution of the same length:

'rd3*>o<

Try it online!

Everyone forgets that a ' acts exactly the same as a ", but has usable divisors. Another 8 byte solution, but considered cheaty by some, 'r00g>o<

Jo King

Posted 2011-01-28T00:34:05.293

Reputation: 5 911

1

This is the same approach I used in the comments of the Original ><> answer: Funnily enough my comment and your post were 1 day off being exactly a year apart.

– Teal pelican – 2018-01-09T16:11:19.690

1

@Tealpelican. Wait, why didn’t we just use a single quote?

– Jo King – 2018-01-19T04:40:52.637

I always forget ><> can use ' or " but ' is so much more useful with having some usable divisors. – Teal pelican – 2018-01-19T09:39:22.957

3

Japt, 9 bytes

I've fantasized about a 9-byte Japt quine for years, and now it's finally snapped into place :-D

9îQi"9îQi

Test it online!

Explanation

    "9îQi    Start with this string.               9îQi
  Qi         Insert it before a quotation mark.    9îQi"
9î           Repeat until it reaches length 9.     9îQi"9îQi

ETHproductions

Posted 2011-01-28T00:34:05.293

Reputation: 42 391

3

Bash, 65 bytes

set -o history
echo "set -o history"
history|tail -n 2|cut -c 8-

Bash disables the command-history function in scripts, but you can turn it on manually with 'set-o history'.

This first command is obviously not stored in the shell's history file, so the second command prints the same text to the terminal.

The third command pulls the last two out of the history file and cleans them up for displaying.

The output matches:

set -o history
echo "set -o history"
history|tail -n 2|cut -c 8-

Kevin

Posted 2011-01-28T00:34:05.293

Reputation: 2 966

reads its source no matter what – Erik the Outgolfer – 2016-06-15T08:39:40.893

3

(ucb)logo - 28 chars

to q
po "q
pr "q
bye
end

q

Geoff Reedy

Posted 2011-01-28T00:34:05.293

Reputation: 2 678

3

ShapeScript, 16 bytes

'"%r"@%"0?!"'0?!

This answer is non-competing, since ShapeScript is a few years younger than this challenge.

Try it online!

Verification

$ shapescript quine.shape | diff -sq - quine.shape
Files - and quine.shape are identical

How it works

'       Push a string that, when evaluated, does the following.
  "%r"  Push this formatting string. %r gets replaced by a string
        representation of the corresponding argument.
  @     Swap the string that is being evaluated on top of the stack.
  %     Apply formatting to the string on top of the stack.
  "0?!" Push that string.
'
0?!     Push a copy of the previous string and evaluate it.

ShapeScript, 32 bytes

'"'"'"'1?3?+3*2?+@+@+@#"0?!"'0?!

This version does not use string formatting. It's not particularly short, but I find it rather interesting.

Try it online!

How it works

'"'     Push a double quote singleton string.
"'"     Push a single quote singleton string.
'       Push a string that, when evaluated, does the following:
  1?3?    Copy the second and fourth topmost stack items.
          This pushes a copy of the single, then the double quote.
  +3*     Concatenate both and repeat the result three times.
  2?+     Copy the third topmost stack item and append it to the string.
          We now have a string of the first seven characters of the source.
  @+      Swap with the string on the stack (the string that is being
          evaluated) and concatenate.
  @+      Swap with the original single quote and concatenate.
  @#      Swap with the original double quote and discard it.
  "0?!"   Push that string.
'
0?!     Push a copy of the above string and evaluate it.

Dennis

Posted 2011-01-28T00:34:05.293

Reputation: 171 923

3

TeaScript, 1 byte

1

Nothing too interesting. But if that's too boring...

TeaScript, 3 bytes

[q|

and if that's to boring...

TeaScript, 15 bytes

(ƒ`(${f})()`)()

Downgoat

Posted 2011-01-28T00:34:05.293

Reputation: 20 837

3

Squeak Smalltalk - 91!

I just translated my Factor answer:

[:b|b value:b]value:[:b|Transcript show: '[:b|b value:b]value:[:b|' , b sourceString , ']']

Just DoIt! in a Workspace, prints itself to the Transcript.

Blocks don't have a reference to self, so i used another block as a combinator.

I'm sure there MUST be a shorter Smalltalk quine! After all it's Small-talk :P

No cheating -- that means that you can't just read the source file and print it.

At first I thought BlockClosure>>sourceString could be cheating as stated in the question, but looking at the Squeak implementation, doesn't seem to be reading the sources file1, but decompiling the block.

1: Smalltalk's image usually saves compiled code, and links to an external file with the original source.

fede s.

Posted 2011-01-28T00:34:05.293

Reputation: 895

It's cheating if b is your whole program. However, if b is a function or string literal, it's fine. – wizzwizz4 – 2016-02-14T09:05:17.410

@wizzwizz4 Thanks for the clarification! – fede s. – 2016-02-14T21:56:55.037

Yeah sourceString looks like "read[ing] the source file and print[ing] it". – Martin Ender – 2016-02-14T22:34:36.023

@MartinBüttner I just checked the implementation, and it decompiles the BlockClosure, it doesn't use the sources file. The message-chain is: sourceString -> self printSourceOn: -> self decompile. Not sure if it's cheating in a general sense, but I think as stated in the question it's legit, right? – fede s. – 2016-02-15T01:17:57.163

1The second largest program I've seen. 91! = 1.352002e+140 :P – user48538 – 2016-05-16T20:29:37.767

@zyabin101 That's weird, I get '91! Argument expected -&gt;' if I printIt. What version of squeak are you using? :P – fede s. – 2016-05-16T20:37:31.500

I'm using Google for that. :P – user48538 – 2016-05-17T09:55:20.420

@fedes. Try: USE: math.factorials 91 n!, you get 135200152767840296255166568759495142147586866476906677791741734597153670771559994765685283954750449427751168336768008192000000000000000000000 :D – cat – 2016-05-17T22:48:42.307

@cat is that a Monticello package? I can't find it on SmalltakHub... you guys make no sense! – fede s. – 2016-05-17T22:56:17.857

1

@fedes. probably needs more jQuery

– cat – 2016-05-17T23:23:41.233

3

Go, 115 bytes

package main;import."fmt";func main(){s:="package main;import.\"fmt\";func main(){s:=%q;Printf(s,s);}";Printf(s,s)}

Blowing the previous Go record out of the water!

EMBLEM

Posted 2011-01-28T00:34:05.293

Reputation: 1 380

Nice job, there! – Conor O'Brien – 2016-03-23T17:53:04.810

3

Python, 104 bytes

Uses eval and repr

a = "print 'a','=', repr(eval('a'))\nprint eval('a'),\n"
print 'a','=', repr(eval('a'))
print eval('a'),

Alexandru

Posted 2011-01-28T00:34:05.293

Reputation: 3 729

1repr(x)==\x`` – CalculatorFeline – 2016-03-10T23:58:28.293

3Since this is code-golf, you might want to include a byte count. – nyuszika7h – 2014-04-28T12:33:08.493

3

Ouroboros, 30 bytes

;T...!59*\1=33*++o.9=\1=2*+(1"

The T should be replaced with a literal tab character.

About Ouroboros

Each line of an Ouroboros program represents a snake eating its own tail, with the beginning of the line being the head and the end being the tail. The only control flow operations are commands to eat or regurgitate characters of the tail. When the instruction pointer reaches the last part of the line that hasn't been eaten, it loops back to the beginning. If the instruction pointer is swallowed, execution halts.

While Ouroboros has some similarities to 2D languages such as ><>, its limited control flow options presented a challenge for quine construction. The only way to skip an instruction is to put it near the end and swallow it--which means instructions near the beginning basically can't be skipped. It took some experimenting before I found a quine structure that worked.

Explanation

The core idea is similar to a ><> or Befunge quine: with a wrapping IP, a single " mark can be used to stringify the code on one pass and execute it on another. Ouroboros automatically pushes strings to the stack in reverse order, which simplifies things. However, we have to put the quotation mark at the end so we can swallow it to avoid pushing the string multiple times. That means that the code must be executed first, then the string pushed, and then the code executed again until the output is complete.

On every pass, the code does two main things: output a character and swallow 0 or more characters of code.

...!59*\1=33*++o

On the first pass, the stack is empty and treated as zero. Logically negating and multiplying by 59 gives the character code for ;, the first character of the quine. On the final pass, the 1 that was pushed right before the string (at the very end of the code) is encountered, to which we add 33 to turn it into 34, the closing ". On other passes, the character code is output unchanged. In pseudocode: output (!top)*59 + (top==1)*33 + top

.9=\1=2*+(

There are two passes on which code needs to be swallowed. On the first pass after we push the string (when we print the tab) the quotation mark has to go; and on the last pass (after we've processed the whole string and the 1 is left on the stack) two more characters are eaten to swallow the instruction pointer and end the program. On every other pass, don't eat anything. In pseudocode: swallow (top==9)+(top==1)*2

One problem remains: since we output the first character of code on the initial pass, we have to drop it (;) immediately after pushing the string so it won't be output a second time. But we don't want to drop anything on subsequent passes. Fortunately, at the end of each iteration we push another 1 to the stack, which is immediately dropped at the beginning of the next pass.

Try it out

// Define Stack class
function Stack() {
  this.stack = [];
  this.length = 0;
}
Stack.prototype.push = function(item) {
  this.stack.push(item);
  this.length++;
}
Stack.prototype.pop = function() {
  var result = 0;
  if (this.length > 0) {
    result = this.stack.pop();
    this.length--;
  }
  return result;
}
Stack.prototype.top = function() {
  var result = 0;
  if (this.length > 0) {
    result = this.stack[this.length - 1];
  }
  return result;
}
Stack.prototype.toString = function() {
  return "" + this.stack;
}

// Define Snake class
function Snake(code) {
  this.code = code;
  this.length = this.code.length;
  this.ip = 0;
  this.ownStack = new Stack();
  this.currStack = this.ownStack;
  this.alive = true;
  this.wait = 0;
  this.partialString = this.partialNumber = null;
}
Snake.prototype.step = function() {
  if (!this.alive) {
    return null;
  }
  if (this.wait > 0) {
    this.wait--;
    return null;
  }
  var instruction = this.code.charAt(this.ip);
  var output = null;
  console.log("Executing instruction " + instruction);
  if (this.partialString !== null) {
    // We're in the middle of a double-quoted string
    if (instruction == '"') {
      // Close the string and push its character codes in reverse order
      for (var i = this.partialString.length - 1; i >= 0; i--) {
        this.currStack.push(this.partialString.charCodeAt(i));
      }
      this.partialString = null;
    } else {
      this.partialString += instruction;
    }
  } else if (instruction == '"') {
    this.partialString = "";
  } else if ("0" <= instruction && instruction <= "9") {
    if (this.partialNumber !== null) {
      this.partialNumber = this.partialNumber + instruction;  // NB: concatenation!
    } else {
      this.partialNumber = instruction;
    }
    next = this.code.charAt((this.ip + 1) % this.length);
    if (next < "0" || "9" < next) {
      // Next instruction is non-numeric, so end number and push it
      this.currStack.push(+this.partialNumber);
      this.partialNumber = null;
    }
  } else if ("a" <= instruction && instruction <= "f") {
    // a-f push numbers 10 through 15
    var value = instruction.charCodeAt(0) - 87;
    this.currStack.push(value);
  } else if (instruction == "$") {
    // Toggle the current stack
    if (this.currStack === this.ownStack) {
      this.currStack = this.program.sharedStack;
    } else {
      this.currStack = this.ownStack;
    }
  } else if (instruction == "s") {
    this.currStack = this.ownStack;
  } else if (instruction == "S") {
    this.currStack = this.program.sharedStack;
  } else if (instruction == "l") {
    this.currStack.push(this.ownStack.length);
  } else if (instruction == "L") {
    this.currStack.push(this.program.sharedStack.length);
  } else if (instruction == ".") {
    var item = this.currStack.pop();
    this.currStack.push(item);
    this.currStack.push(item);
  } else if (instruction == "m") {
    var item = this.ownStack.pop();
    this.program.sharedStack.push(item);
  } else if (instruction == "M") {
    var item = this.program.sharedStack.pop();
    this.ownStack.push(item);
  } else if (instruction == "y") {
    var item = this.ownStack.top();
    this.program.sharedStack.push(item);
  } else if (instruction == "Y") {
    var item = this.program.sharedStack.top();
    this.ownStack.push(item);
  } else if (instruction == "\\") {
    var top = this.currStack.pop();
    var next = this.currStack.pop()
    this.currStack.push(top);
    this.currStack.push(next);
  } else if (instruction == "@") {
    var c = this.currStack.pop();
    var b = this.currStack.pop();
    var a = this.currStack.pop();
    this.currStack.push(c);
    this.currStack.push(a);
    this.currStack.push(b);
  } else if (instruction == ";") {
    this.currStack.pop();
  } else if (instruction == "+") {
    var b = this.currStack.pop();
    var a = this.currStack.pop();
    this.currStack.push(a + b);
  } else if (instruction == "-") {
    var b = this.currStack.pop();
    var a = this.currStack.pop();
    this.currStack.push(a - b);
  } else if (instruction == "*") {
    var b = this.currStack.pop();
    var a = this.currStack.pop();
    this.currStack.push(a * b);
  } else if (instruction == "/") {
    var b = this.currStack.pop();
    var a = this.currStack.pop();
    this.currStack.push(a / b);
  } else if (instruction == "%") {
    var b = this.currStack.pop();
    var a = this.currStack.pop();
    this.currStack.push(a % b);
  } else if (instruction == "_") {
    this.currStack.push(-this.currStack.pop());
  } else if (instruction == "I") {
    var value = this.currStack.pop();
    if (value < 0) {
      this.currStack.push(Math.ceil(value));
    } else {
      this.currStack.push(Math.floor(value));
    }
  } else if (instruction == ">") {
    var b = this.currStack.pop();
    var a = this.currStack.pop();
    this.currStack.push(+(a > b));
  } else if (instruction == "<") {
    var b = this.currStack.pop();
    var a = this.currStack.pop();
    this.currStack.push(+(a < b));
  } else if (instruction == "=") {
    var b = this.currStack.pop();
    var a = this.currStack.pop();
    this.currStack.push(+(a == b));
  } else if (instruction == "!") {
    this.currStack.push(+ !this.currStack.pop());
  } else if (instruction == "?") {
    this.currStack.push(Math.random());
  } else if (instruction == "n") {
    output = "" + this.currStack.pop();
  } else if (instruction == "o") {
    output = String.fromCharCode(this.currStack.pop());
  } else if (instruction == "r") {
    var input = this.program.io.getNumber();
    this.currStack.push(input);
  } else if (instruction == "i") {
    var input = this.program.io.getChar();
    this.currStack.push(input);
  } else if (instruction == "(") {
    this.length -= Math.floor(this.currStack.pop());
    this.length = Math.max(this.length, 0);
  } else if (instruction == ")") {
    this.length += Math.floor(this.currStack.pop());
    this.length = Math.min(this.length, this.code.length);
  } else if (instruction == "w") {
    this.wait = this.currStack.pop();
  }
  // Any unrecognized character is a no-op
  if (this.ip >= this.length) {
    // We've swallowed the IP, so this snake dies
    this.alive = false;
    this.program.snakesLiving--;
  } else {
    // Increment IP and loop if appropriate
    this.ip = (this.ip + 1) % this.length;
  }
  return output;
}
Snake.prototype.getHighlightedCode = function() {
  var result = "";
  for (var i = 0; i < this.code.length; i++) {
    if (i == this.length) {
      result += '<span class="swallowedCode">';
    }
    if (i == this.ip) {
      if (this.wait > 0) {
        result += '<span class="nextActiveToken">';
      } else {
        result += '<span class="activeToken">';
      }
      result += escapeEntities(this.code.charAt(i)) + '</span>';
    } else {
      result += escapeEntities(this.code.charAt(i));
    }
  }
  if (this.length < this.code.length) {
    result += '</span>';
  }
  return result;
}

// Define Program class
function Program(source, speed, io) {
  this.sharedStack = new Stack();
  this.snakes = source.split(/\r?\n/).map(function(snakeCode) {
    var snake = new Snake(snakeCode);
    snake.program = this;
    snake.sharedStack = this.sharedStack;
    return snake;
  }.bind(this));
  this.snakesLiving = this.snakes.length;
  this.io = io;
  this.speed = speed || 10;
  this.halting = false;
}
Program.prototype.run = function() {
  this.step();
  if (this.snakesLiving) {
    this.timeout = window.setTimeout(this.run.bind(this), 1000 / this.speed);
  }
}
Program.prototype.step = function() {
   for (var s = 0; s < this.snakes.length; s++) {
    var output = this.snakes[s].step();
    if (output) {
      this.io.print(output);
    }
  }
  this.io.displaySource(this.snakes.map(function (snake) {
      return snake.getHighlightedCode();
    }).join("<br>"));
 }
Program.prototype.halt = function() {
  window.clearTimeout(this.timeout);
}

var ioFunctions = {
  print: function (item) {
    var stdout = document.getElementById('stdout');
    stdout.value += "" + item;
  },
  getChar: function () {
    if (inputData) {
      var inputChar = inputData[0];
      inputData = inputData.slice(1);
      result = inputChar.charCodeAt(0);
    } else {
      result = -1;
    }
    var stdinDisplay = document.getElementById('stdin-display');
    stdinDisplay.innerHTML = escapeEntities(inputData);
    return result;
  },
  getNumber: function () {
    while (inputData && (inputData[0] < "0" || "9" < inputData[0])) {
      inputData = inputData.slice(1);
    }
    if (inputData) {
      var inputNumber = inputData.match(/\d+/)[0];
      inputData = inputData.slice(inputNumber.length);
      result = +inputNumber;
    } else {
      result = -1;
    }
    var stdinDisplay = document.getElementById('stdin-display');
    stdinDisplay.innerHTML = escapeEntities(inputData);
    return result;
  },
  displaySource: function (formattedCode) {
    var sourceDisplay = document.getElementById('source-display');
    sourceDisplay.innerHTML = formattedCode;
  }
};
var program = null;
var inputData = null;
function showEditor() {
  var source = document.getElementById('source'),
    sourceDisplayWrapper = document.getElementById('source-display-wrapper'),
    stdin = document.getElementById('stdin'),
    stdinDisplayWrapper = document.getElementById('stdin-display-wrapper');
  
  source.style.display = "block";
  stdin.style.display = "block";
  sourceDisplayWrapper.style.display = "none";
  stdinDisplayWrapper.style.display = "none";
  
  source.focus();
}
function hideEditor() {
  var source = document.getElementById('source'),
    sourceDisplay = document.getElementById('source-display'),
    sourceDisplayWrapper = document.getElementById('source-display-wrapper'),
    stdin = document.getElementById('stdin'),
    stdinDisplay = document.getElementById('stdin-display'),
    stdinDisplayWrapper = document.getElementById('stdin-display-wrapper');
  
  source.style.display = "none";
  stdin.style.display = "none";
  sourceDisplayWrapper.style.display = "block";
  stdinDisplayWrapper.style.display = "block";
  
  var sourceHeight = getComputedStyle(source).height,
    stdinHeight = getComputedStyle(stdin).height;
  sourceDisplayWrapper.style.minHeight = sourceHeight;
  sourceDisplayWrapper.style.maxHeight = sourceHeight;
  stdinDisplayWrapper.style.minHeight = stdinHeight;
  stdinDisplayWrapper.style.maxHeight = stdinHeight;
  sourceDisplay.textContent = source.value;
  stdinDisplay.textContent = stdin.value;
}
function escapeEntities(input) {
  return input.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}
function resetProgram() {
  var stdout = document.getElementById('stdout');
  stdout.value = null;
  if (program !== null) {
    program.halt();
  }
  program = null;
  inputData = null;
  showEditor();
}
function initProgram() {
  var source = document.getElementById('source'),
    stepsPerSecond = document.getElementById('steps-per-second'),
    stdin = document.getElementById('stdin');
  program = new Program(source.value, +stepsPerSecond.innerHTML, ioFunctions);
  hideEditor();
  inputData = stdin.value;
}
function runBtnClick() {
  if (program === null || program.snakesLiving == 0) {
    resetProgram();
    initProgram();
  } else {
    program.halt();
    var stepsPerSecond = document.getElementById('steps-per-second');
    program.speed = +stepsPerSecond.innerHTML;
  }
  program.run();
}
function stepBtnClick() {
  if (program === null) {
    initProgram();
  } else {
    program.halt();
  }
  program.step();
}
function sourceDisplayClick() {
  resetProgram();
}
.container {
    width: 100%;
}
.so-box {
    font-family:'Helvetica Neue', Arial, sans-serif;
    font-weight: bold;
    color: #fff;
    text-align: center;
    padding: .3em .7em;
    font-size: 1em;
    line-height: 1.1;
    border: 1px solid #c47b07;
    -webkit-box-shadow: 0 2px 2px rgba(0, 0, 0, 0.3), 0 2px 0 rgba(255, 255, 255, 0.15) inset;
    text-shadow: 0 0 2px rgba(0, 0, 0, 0.5);
    background: #f88912;
    box-shadow: 0 2px 2px rgba(0, 0, 0, 0.3), 0 2px 0 rgba(255, 255, 255, 0.15) inset;
}
.control {
    display: inline-block;
    border-radius: 6px;
    float: left;
    margin-right: 25px;
    cursor: pointer;
}
.option {
    padding: 10px 20px;
    margin-right: 25px;
    float: left;
}
h1 {
    text-align: center;
    font-family: Georgia, 'Times New Roman', serif;
}
a {
    text-decoration: none;
}
input, textarea {
    box-sizing: border-box;
}
textarea {
    display: block;
    white-space: pre;
    overflow: auto;
    height: 50px;
    width: 100%;
    max-width: 100%;
    min-height: 25px;
}
span[contenteditable] {
    padding: 2px 6px;
    background: #cc7801;
    color: #fff;
}
#stdout-container, #stdin-container {
    height: auto;
    padding: 6px 0;
}
#reset {
    float: right;
}
#source-display-wrapper , #stdin-display-wrapper{
    display: none;
    width: 100%;
    height: 100%;
    overflow: auto;
    border: 1px solid black;
    box-sizing: border-box;
}
#source-display , #stdin-display{
    font-family: monospace;
    white-space: pre;
    padding: 2px;
}
.activeToken {
    background: #f93;
}
.nextActiveToken {
    background: #bbb;
}
.swallowedCode{
    color: #999;
}
.clearfix:after {
    content:".";
    display: block;
    height: 0;
    clear: both;
    visibility: hidden;
}
.clearfix {
    display: inline-block;
}
* html .clearfix {
    height: 1%;
}
.clearfix {
    display: block;
}
<!--
Designed and written 2015 by D. Loscutoff
Much of the HTML and CSS was taken from this Befunge interpreter by Ingo Bürk: http://codegolf.stackexchange.com/a/40331/16766
-->
<div class="container">
<textarea id="source" placeholder="Enter your program here" wrap="off">; ...!59*\1=33*++o.9=\1=2*+(1"</textarea>
<div id="source-display-wrapper" onclick="sourceDisplayClick()"><div id="source-display"></div></div></div><div id="stdin-container" class="container">
<textarea id="stdin" placeholder="Input" wrap="off"></textarea>
<div id="stdin-display-wrapper" onclick="stdinDisplayClick()"><div id="stdin-display"></div></div></div><div id="controls-container" class="container clearfix"><input type="button" id="run" class="control so-box" value="Run" onclick="runBtnClick()" /><input type="button" id="pause" class="control so-box" value="Pause" onclick="program.halt()" /><input type="button" id="step" class="control so-box" value="Step" onclick="stepBtnClick()" /><input type="button" id="reset" class="control so-box" value="Reset" onclick="resetProgram()" /></div><div id="stdout-container" class="container"><textarea id="stdout" placeholder="Output" wrap="off" readonly></textarea></div><div id="options-container" class="container"><div class="option so-box">Steps per Second:
<span id="steps-per-second" contenteditable>20</span></div></div>

DLosc

Posted 2011-01-28T00:34:05.293

Reputation: 17 064

3

BaCon, 55 bytes

Without using the SOURCE$ variable, the smallest Quine is 55 bytes:

s$="s$=%c%s%c:?34,s$,34 FORMAT s$":?34,s$,34 FORMAT s$

Peter

Posted 2011-01-28T00:34:05.293

Reputation: 109

2please make the main part of the post the 55 byte noncheating quine – Destructible Lemon – 2016-10-14T21:05:00.643

Done. I wonder why using 'SOURCE$' is cheating, looking at the other contributions? – Peter – 2016-10-15T20:05:24.100

1

The other answers are also cheating. This challenge is over five years old; most answers were posted before we had clearly defined rules. Since last month, improper quines are officially forbidden in all challenges, even if the spec doesn't explicitly forbid them.

– Dennis – 2016-10-15T20:13:29.807

Thanks for pointing me to this page, I was unaware of it. – Peter – 2016-10-16T20:29:20.193

The smallest BaCon quine is 55 bytes? Guess again.

– MD XF – 2017-05-26T15:40:07.340

3

Turtlèd, 68 63 53 54 bytes (newlines)

rewrote

@##'@r,r,r-{ +.r_}r{ +.r_}'#'@r,r,r-{ +.r_}r{ +.r_}'f

Try it online!

Explanation

@#         Set character variable to #. Useful because this cannot occur in string var     
  #                        #  Set the string var to...
   '@r,r,r-{ +.r_}r{ +.r_}'   This string (quotes included. coincidental)
                            '@r,r,r            Write out first three chars of program: @##
                                   -{ +.r_}r   Write out the string var, then #, move right
                                            { +.r_} Write out the string var again, write #
                                                   'f   overwrite last # with f

Destructible Lemon

Posted 2011-01-28T00:34:05.293

Reputation: 4 669

3

MATL, 12 11 bytes

'&DtU'
&DtU

Try it online!

Explanation

'&DtU'    % Push this string
&D        % String representation (adds quote marks)
t         % Duplicate
U         % Evaluate (removes quote marks)
          % Implicitly display each string on a different line

Luis Mendo

Posted 2011-01-28T00:34:05.293

Reputation: 68 100

I take it that it would not be shorter to do &amp;D after t, avoiding U? – ETHproductions – 2016-10-23T02:56:59.510

@ETHproductions Not sure if I understand your suggestion correctly. I think &amp;D needs to be after t because the second part of the displayed output needs to be without quotes – Luis Mendo – 2016-10-23T03:00:37.903

1I mean that unevaling the string &amp;D and then re-evaling U seems a little redundant. It's probably not shorter any other way, though, as you would likely need to use stack manipulation. – ETHproductions – 2016-10-23T03:03:32.957

@ETHproductions Oh, now I see what you mean: this, right? (w is swap). As you say, it's not shorter unfortunately

– Luis Mendo – 2016-10-23T03:08:14.197

Yeah, that's what I meant, and that's what I figured – ETHproductions – 2016-10-23T03:09:41.540

2

Pushy, 9 bytes

95 34
_"

(non-competing as the language postdates the challenge)

Although writing functional programs in Pushy is sometimes difficult, the quine is relatively simple:

95   % Push 95 to the stack (ASCII code for _ )
34   % Push 34 to the stack (ASCII code for " )
_    % Print representation of the stack: 95 34
"    % Print stack converted to string: _"

Notice that, although Pushy ignores newlines, it is needed here because the default separator for printing is \n - and there needs to be a trailing newline, hence making it 9 bytes


Alternatively, an 11-byte solution that does not require a newline:

78 95 34N_"

Works similarly to the one above, but N sets the separator an empty string.

FlipTack

Posted 2011-01-28T00:34:05.293

Reputation: 8 743

2

V, 4 bytes

2i2i

Try it online!

Marked as non-competing because this language postdates the challenge by several years.

Explanation:

2       " Two times:
 i      " Insert the following:
  2i    " The string '2i'

This is pretty straightforward. In fact, this almost works in regular vim. There is just one minor thing in the way: The string '2i' isn't inserted twice until you hit <esc>. In V, this is solved by implicitly ending every program with an <esc> (Really, that's an oversimplification, but it's close enough to the truth).

Old versions of V always added a newline to the output, which is why I didn't post this earlier. However, in commit b6c238d, this was fixed.

This answer works just because of luck. The approach doesn't extend well to general purpose quines/quine-variations. The shortest quine I'm aware of that can be trivially modified is

ñéÑ~"qpÿ

Try it online!

Explanation:

ñ           " Start recording into register 'q'
 éÑ         " Insert 'Ñ' (uppercase so that the recording doesn't stop here)
   ~        " Toggle the case the character under the cursor (the 'Ñ')
    "qp     " Paste the contents of register 'q'
       ÿ    " Stop recording and play it all back

The reason the ÿ is needed, is because it is implicitly added to the end of macros, a feature that is unfortunate for quines, but very convenient for golf.

The nice thing about this quine is that we can do almost anything inside of the recording and it is still valid since it will be pasted later anyway.

DJMcMayhem

Posted 2011-01-28T00:34:05.293

Reputation: 37 405

2

Cheddar, 56 bytes

Try this one online!

let q='let q=%s%s%s;print IO.sprintf(q,@"39,q,@"39)';print IO.sprintf(q,@"39,q,@"39)

See the explanation below, except mentally replace % with IO.sprintf.




Well darn. @ETHProductions came up with this solution before me..

This is the shortest I could come up with... Maybe some abuse of functional operators could help me.

let q='let q=%s;print q%@"39+q+@"39';print q%@"39+q+@"39

Try it online! You can guess what the output is.

This code can be divided into two parts: the string and the output. The string part:

let q='let q=%s;print q%@"39+q+@"39';

is simply a formatting template.

The output part:

;print q%@"39+q+@"39

formats the string. @"39 is char 39, or '.

Conor O'Brien

Posted 2011-01-28T00:34:05.293

Reputation: 25 859

2

Java 8, 94 bytes

()->{String s="()->{String s=%c%s%1$c;System.out.printf(s,34,s);}";System.out.printf(s,34,s);}

This is a lambda expression which prints its own source code to STDOUT. It uses a similar tactic to other Java quines here, but the lambda really helps cut down bytes.

If we wanted to be really cheeky and cut down two bytes, we could declare the lambda as x->, where x is an empty string, as according to meta, "taking no input" means you can assume empty input, and in function submissions input is given as a parameter.

FlipTack

Posted 2011-01-28T00:34:05.293

Reputation: 8 743

2

Python 3, 38 bytes

There are already a lot of Python quines, but as far as I can see this one hasn't been posted yet. Technically it is a statement that evaluates to a string representation of itself, but other submissions do similar things.

'.__repr__()[:-1]*2'.__repr__()[:-1]*2

This works in a similar way to many quines in 2D langauges with "edge-wrap", where "string mode" is entered, the whole program is pushed to the stack, then string mode is executed and the program runs, printing the string mode character (usually ") followed by the contents of the stack (i.e. the program's source) then exiting.

A breakdown of the statement is as follows:

'.__repr__()[:-1]*2'                   # A string containing the body of the program.
                                       # .__repr__()[:-1]*2
                    .__repr__()        # The same string, but enclosed in single quote marks.
                                       # '.__repr__()[:-1]*2'
                               [:-1]   # A splice that crops off the last character.
                                       # '.__repr__()[:-1]*2
                                    *2 # Repeat the string.
                                       # '.__repr__()[:-1]*2'.__repr__()[:-1]*2

The reason I have used .__repr__() instead of repr(string) is because the quine relies on code following and not preceding the string. This is also why this is a statement and not a program; the print() function requires code before the string, which is not possible with this quine layout.

As you may have noticed, there's a much golfier statement that evaluates to this statement:

"'.__repr__()[:-1]*2"*2

But this isn't a quine, because it doesn't evaluate to itself.

wizzwizz4

Posted 2011-01-28T00:34:05.293

Reputation: 1 134

1Unfortunately, I don't think this is valid, since it's an expression (and therefore a snippet) rather than a full program. – Esolanging Fruit – 2017-07-30T02:33:17.127

2

Threead, 101 bytes

>91>60>93>62>91>105>54>50>99>111>100>111>62>93>60>91>60>93>62>91>99>111>62>93[<]>[i62codo>]<[<]>[co>]

Try it online!

My first thought for writing a Threead quine was to store the entire data section as one large number, in order to get a good compression ratio. This doesn't work because a) % appears to be broken, and b) Threead doesn't support bignum arithmetic.

Instead, I wrote this solution, which works along the same lines as a brainfuck quine, storing the characters of the code section of the program as individual tape elements. Then we just have to scan the list once in order to print it as data, and again to print it as code.

Although Threead allows for three threads, and requires their use when performing binary operations, this style of quine uses only unary operations and thus there was no point in using more than one thread, so I just did everything inside the first.

Explanation

>91>60>…>62>93            ASCII character codes of the rest of the program
[<]>                      Return the pointer to the start of the data
[                         While the current data cell is nonzero:
 i62                        Place 62 (ASCII code of >) on a temporary tape cell
 co                         Output it as a character (i.e. >)
 d                          Delete the temporary tape cell
 o                          Output the current data element as an integer
>]                        then continue the loop with the next data cell
<[<]>                     Return the pointer to the start of the data
[                         While the current data cell is nonzero:
 co                         Output it as a character
>]                        then continue the loop with the next data cell

user62131

Posted 2011-01-28T00:34:05.293

Reputation:

Nice. Basically the same as mine but with &gt; at the beginning. I like it

– Riley – 2017-01-16T23:01:00.467

I hope you don't mind that I used that trick in my new version :) – Riley – 2017-01-16T23:23:54.583

@Riley: That's OK, we're pretty much all cooperating to improve the quine at this point. – None – 2017-01-16T23:25:03.443

2

brainfuck with ! extension, 71 39 32 bytes

-32 thanks to Jo King
-7 thanks to Jo King
This answer has pretty much entirely been written by Jo King by now.

,[.>,]<[<]>[.>]!,[.>,]<[<]>[.>]!

This requires an implementation where ! marks the separation between code and input (and that allows the input to contain further !).

Esolanging Fruit

Posted 2011-01-28T00:34:05.293

Reputation: 6 495

I'm not sure if any such implementations exist, but this clearly violates the rule that you're not allowed to read the source code. – Martin Ender – 2017-04-02T22:03:18.670

@MartinEnder Maybe the implementation is reading the source code, not the program. – Esolanging Fruit – 2017-04-02T22:07:50.140

sure, I can claim that for every program that reads its own source code. You're accessing memory that holds the program's source code. That's reading your own source code. Also, any BF-program using , violates the "takes no input" rule. – Martin Ender – 2017-04-02T22:10:04.117

If the implementation says that the ! denotes input, than the second half is input and this answer is invalid. – Jo King – 2018-02-23T10:02:23.530

But if you insist on keeping it, 39 bytes ,[.&gt;,]&lt;+.-[&lt;]&gt;[.&gt;] !,[.&gt;,]&lt;+.-[&lt;]&gt;[.&gt;] – Jo King – 2018-02-23T10:03:34.373

@JoKing Thanks, edited. – Esolanging Fruit – 2018-02-24T04:16:48.363

Actually, ,[.&gt;,]&lt;[&lt;]&gt;[.&gt;]!,[.&gt;,]&lt;[&lt;]&gt;[.&gt;]! works if you're allowed multiple !s – Jo King – 2018-03-01T07:23:57.843

Because the second part after the ! encodes both itself and the first part, this is a valid quine. – user202729 – 2018-03-03T13:40:30.193

2

Alice, 9 bytes

Credits to Sp3000 for the idea of including the !.

"!<@o&9h.

Try it online!

Explanation

This works much like quines in other Fungeoids with an unmatched " that wraps the entire code (except itself) in a string because the instruction pointer move cyclically through the code.

"!<@o&9h."   Push code points of the entire program except the " to the
             stack (irrelevant).
!            Store 46 (the code point of '.') on the tape (irrelevant).
<            Send IP back west.
!            Store 104 (the code point of 'h') on the tape (irrelevant).
".h9&o@<!"   Push code points of the entire program except the " to the
             stack in reverse.
.            Duplicate the 33 (the code point of '!').
h            Increment to 34 (the code point of '"').
             Now the top nine values on the stack correspond to the entire
             code in reverse order.
9&           Repeat the next command 9 times.
o            Print 9 characters from the top of the stack.
@            Terminate the program.

Martin Ender

Posted 2011-01-28T00:34:05.293

Reputation: 162 549

2

Ohm, 22 20 bytes

-2 bytes thanks to Business Cat

"D34'DLaJL"D34'DLaJL

Try it online!

"D34'DLaJL"          # Push this string (everything after this)
           D         # Duplicate
            34'      # Push the character "
               D     # Duplicate
                L    # Print "
                 a   # Swap the top 2 elements 
                  JL # Print the string, ", then the string again.

Riley

Posted 2011-01-28T00:34:05.293

Reputation: 10 445

You can save 2 bytes by replacing LLL with JL (in both occurrences). – Business Cat – 2017-05-18T17:56:58.027

@BusinessCat Thanks! – Riley – 2017-05-18T18:01:43.130

2

Awk, 64 bytes

BEGIN{c="BEGIN{c=%c%s%c;printf c,34,c,34}";printf c,34,c,34}

MD XF

Posted 2011-01-28T00:34:05.293

Reputation: 8 337

2

ACL2, 41 bytes

(let((q"(let((q~x0))(cw q q))"))(cw q q))

MD XF

Posted 2011-01-28T00:34:05.293

Reputation: 8 337

2

BaCon, 54 bytes

s$="s$=%c%s%c:?34,s$,34 FORMAT s$":?34,s$,34 FORMAT s$

MD XF

Posted 2011-01-28T00:34:05.293

Reputation: 8 337

2

Go, 112 bytes

As far as I can tell, there's no Go answer here. Here's mine and I think this is the shortest possible.

package main;import.`fmt`;func main(){s:="package main;import.`fmt`;func main(){s:=%q;Printf(s,s)}";Printf(s,s)}

Try it online!

totallyhuman

Posted 2011-01-28T00:34:05.293

Reputation: 13 394

2

Kotlin, 121 bytes

Nobody cared enough about Kotlin to post it so...

fun main(a:Array<String>){val s="fun main(a:Array<String>){val s=%c%s%1$1c;print(s.format(34,s))}";print(s.format(34,s))}

Try it online!

totallyhuman

Posted 2011-01-28T00:34:05.293

Reputation: 13 394

2

QBIC, 8 bytes

?A+@?A+@

I was trying to do this, but I accidentally golfed an actual quine. Whadda you know?

Explanation

?           Print
 A            A$
  +         concatenated with
   @       a string literal containing
    ?A+@   "?A+@"

When A$ is used the first time, it might not seem to have a value yet, but it already contains the string literal ?A+@ because the QBIC interpreter first scans the code, sees the @, looks up what the first available string variable is (it's A$, because it hasn't been used by other QBIC language features yet), and it then extracts the definition A$ = "?A+@" to the top of the file, and inserts A$ at the place where it found the literal.

steenbergh

Posted 2011-01-28T00:34:05.293

Reputation: 6 474

2

Micro, 5 bytes

{_BS}

Explination:

{_BS}

{      start a code block (this block will be run due to implicit evaluation)
 _     push the item most recently popped. this pushes the code block which was popped due to implicit evaluation
  BS}  convert the code block to a string, and end the block. Micro's implicit evaluation is weird, because the evaluated variable may generate new items on the stack, in which case the program's execution will continue as if it hadn't ended. this second implicit evaluation displays the string which is left on the stack: "{_BS}", and ends execution.

raddish0

Posted 2011-01-28T00:34:05.293

Reputation: 81

2

JScript, 175 bytes

WScript.Echo((k="WScript.Echo((k=\"%Z\").replace(/%[Z]/,k.replace(/[\"\\\\]/g,function(e){return\"\\\\\"+e})))").replace(/%[Z]/,k.replace(/["\\]/g,function(e){return"\\"+e})))

JScript is Microsoft's implementation of the JavaScript language. On a microsoft console, you can invoke the program as <name>.js, and this will output to a popup. To output to the console, one must use:

cscript //E:JScript //nologo <name>.js

and add a trailing CRLF to the source code.

Conor O'Brien

Posted 2011-01-28T00:34:05.293

Reputation: 25 859

2

Zsh, 17 bytes

sed p<<a
sed p<<a

jimmy23013

Posted 2011-01-28T00:34:05.293

Reputation: 25 688

2

Foam, 15 bytes

[. <' |: ~|]: ~

This prints itself with a trailing newline. Without a trailing newline:

[. .' |: ~|]: ~

Esolanging Fruit

Posted 2011-01-28T00:34:05.293

Reputation: 6 495

2

Gaia, 10 bytes

“:ṙpp”:ṙpp

Try it online!

Explanation

“:ṙpp”      Push this string.
      :     Copy it.
       ṙ    Get the string representation of it.
        p   Print the string representation.
         p  Print the string.

Business Cat

Posted 2011-01-28T00:34:05.293

Reputation: 8 357

2

Proton, 32 30 bytes

-2 bytes thanks to ppperry.

s='s=%rprint(s%%s)'print(s%s)

Try it online!

I swear, if I get a bounty for this...

totallyhuman

Posted 2011-01-28T00:34:05.293

Reputation: 13 394

Hey, I promised a bounty, so if nobody beats it, good for you I guess :P – HyperNeutrino – 2017-08-17T19:39:38.840

1You can save two bytes by deleting the semicolons – ppperry – 2017-08-18T22:18:16.503

2

C (tcc), 64 bytes

main(t){printf(t,34,t="main(t){printf(t,34,t=%c%s%c,34);}",34);}

Try it online!

could be one problem if compiler not use the stack based way of push arguments.
result of the print (tcc, gcc all in TIO today at last ok (not ok in clang)):

main(t){printf(t,34,t="main(t){printf(t,34,t=%c%s%c,34);}",34);}

RosLuP

Posted 2011-01-28T00:34:05.293

Reputation: 1 422

Related – No one – 2017-12-23T19:09:37.610

2

MaybeLater, 74 bytes

x="write(('x='+chr(34))+x+(chr(34))+x)"write(('x='+chr(34))+x+(chr(34))+x)

Try it online!

ATaco

Posted 2011-01-28T00:34:05.293

Reputation: 6 373

2

Java 8 - 392 bytes

interface Q{static void main(String[]a){p("interface Q{static void main(String[]a){p(");q(");}static void p(String s){System.out.print(s+(char)34+s+(char)34+')'+';'+'q'+'('+(char)34);}static void q(String s){System.out.print(s+(char)34+s);}}");}static void p(String s){System.out.print(s+(char)34+s+(char)34+')'+';'+'q'+'('+(char)34);}static void q(String s){System.out.print(s+(char)34+s);}}

The main trick with this was using 34 cast to a character for the quotes that bound the string literals in order to not run into issues.

the_evictor

Posted 2011-01-28T00:34:05.293

Reputation: 21

3Welcome to PPCG! – Steadybox – 2018-01-09T15:53:52.203

2

Wumpus, 9 bytes

"#34#9&o@

Try it online!

Explanation

This is a fairly standard Fungeoid quine. However, as opposed to most other Fungeoids, Wumpus's grid doesn't wrap around, so the IP actually bounces back and forth through the code:

"#34#9&o@o&9#32#"
     This pushes the individual code points of this string to the stack.
#34  Push 34.
#9   Push 9.
&o   Print 9 characters from the top of the stack.
@    Terminate the program.

There are several other ways to do this in 9 bytes, e.g. this one which generates the " from the # instead:

"#9[(~&o@

I haven't yet found a way to get it down to 8 bytes though (it might be possible: if there's a way to generate the 34 in three bytes that doesn't end in a digit, we could get rid of the # in front of the 9).

Martin Ender

Posted 2011-01-28T00:34:05.293

Reputation: 162 549

2

Underload, 10 Bytes

(:aSS):aSS

Try it online!

Wurlitzer

Posted 2011-01-28T00:34:05.293

Reputation: 79

2

Rust, 108 characters

macro_rules!f(()=>("macro_rules!f(()=>({:?}));fn main(){{print!(f!(),f!())}}"));fn main(){print!(f!(),f!())}

This is a suboptimal solution, but it's so close to the current shortest solution that I wanted to post it anyway as it uses a completely different strategy. I think it can be optimized by using macro keyword instead of verbose macro_rules! when it becomes stable (which would reduce this to 96 characters).

xfix

Posted 2011-01-28T00:34:05.293

Reputation: 9 392

2

Zozotez Lisp: 73

((\ (x) (c x (c (c (" ") (c x))))) (" (\ (x) (c x (c (c (" ") (c x)))))))

This requires one of the REPLs. For one bootstrap expression quine I need it to print: 81

((\ (x) (p (c x (c (c (" ") (c x)))))) (" (\ (x) (p (c x (c (c (" ") (c x))))))))

Extended BrainFuck: 68

This uses mostly Brainfuck code except for the store string procedure.

>~"~!<<.[<]>.>+.-<[.>]<[<]>>+.->[.>]"<<.[<]>.>+.-<[.>]<[<]>>+.->[.>]

A 94 byte version that uses more EBF features:

{c|"{q$q.$p(-)}:q:p$q 34+$p|'{c|'&q&c&q|'}'(-)&c"}{q$q.$p(-)}:q:p$q 34+$p|'{c|'&q&c&q|'}'(-)&c

Sylwester

Posted 2011-01-28T00:34:05.293

Reputation: 3 458

2

Haskell, 93 68 characters

s="\nmain=putStrLn$\"s=\"++show s++s"
main=putStrLn$"s="++show s++s

hammar

Posted 2011-01-28T00:34:05.293

Reputation: 3 754

2

Java (229 Characters)

class Main{public static void main(String[]args){char q='"';String s="class Main{public static void main(String[]args){char q='%c';String s=%c%s%c;System.out.print(s.format(s,q,q,s,q));}}";System.out.print(s.format(s,q,q,s,q));}}

Steve P

Posted 2011-01-28T00:34:05.293

Reputation: 131

@Justin Technically, 12 bytes saving. – driima – 2016-11-01T08:59:11.697

4You can shorten it by naming your class a one character name (such as q for quine). Also, there is no need for main(String[]args), just do something like main(String[]a) (total savings: 6 chars) – Justin – 2013-12-11T23:51:48.510

1Try renaming your class? – Timtech – 2014-10-27T19:36:40.830

2

Node.js REPL (22)

console.log(RegExp.$1)

nyuszika7h

Posted 2011-01-28T00:34:05.293

Reputation: 1 561

You need to specify the Node version this works in, because running in 7.5.0, this prints a single newline. – Patrick Roberts – 2017-07-16T05:21:32.837

...this abuses the fact that (I guess) the Node REPL internally executes a regex on the received line? I want to upvote because of the cleverness, but on the other hand I don't want to since it relies on extracting its own source code as a string... – FireFly – 2014-08-22T15:38:36.947

2

MATLAB, 95 characters

There might be shorter ones, but I'm happy that it works at all.

function d=g();d='gvodujpo!e>h)*<e>(<e>\e)2;29*.2-e-e)29;foe*.2^<';d=[d(1:18)-1,d,d(18:end)-1];

Cleaner approach, exact same length:

function d=g();d='function d=g();d=[d(1:17),39,d,39,d(15:end)];';d=[d(1:17),39,d,39,d(15:end)];

knedlsepp

Posted 2011-01-28T00:34:05.293

Reputation: 266

2

Mathcad, 94 characters

f:(c{"f:(c{"")]concat(substr(c,0,6),c,substr(c,6,41))")]concat(substr(c,0,6),c,substr(c,6,41))

Watch out for quotation marks autocompletion in the editor!

This should create a parameterless function f which returns its own code.

This quine makes use of (another) weird feature of Mathcad: you can put as much quotation marks inside a string as you like. No idea how they handle it...

Mints97

Posted 2011-01-28T00:34:05.293

Reputation: 551

2

Bash, 67/51 chars

f () 
{ 
    printf "%s\n${!1} $1" "$(local -f ${!1})"
}
f FUNCNAME

And 51 chars:

trap -- 'printf "%s\n:" "$(trap -p DEBUG)"' DEBUG
:

ormaaj

Posted 2011-01-28T00:34:05.293

Reputation: 153

2

Pyth, 11 bytes

jN*2]"jN*2]

Surprised this hadn't been posted yet :P

TheInitializer

Posted 2011-01-28T00:34:05.293

Reputation: 513

2

SWI-Prolog, 22 bytes

a :-
        listing(a).
 

A surprisingly short and elegant solution.

The 8 spaces and the new line (the space in the last line is just to display the empty line, there is actually no space) are both required in SWI-Prolog because that is the formatting that listing displays in the interpreter.

Fatalize

Posted 2011-01-28T00:34:05.293

Reputation: 24 736

2

Brachylog, 3 bytes

@Qw

This expects no input or output, i.e. brachylog_main(_,_)..

@Q is the string "@Qw", and w is the write predicate.

A 34 bytes quine without a specific built-in for quines

"~c~s~cS:[34:S:34]rw"S:[34:S:34]rw

This is a basic quine strategy applied to this language:

"~c~s~cS:[34:S:34]rw"              § Create a string containing the source code
                                   § ~c~s~c gets replaced by the arguments of predicate w
                                   § in their respective order in the list
                                   § ~c prints the arg as a char code, ~s as a string
                     S             § Call this string S
                      :[34:S:34]rw § Write the format S to the output with args " (34),
                                   § S and " replacing ~c, ~s and ~c respectively

Fatalize

Posted 2011-01-28T00:34:05.293

Reputation: 24 736

2

C#, 188 157 149 bytes

class A{static void Main(){var a="class A{{static void Main(){{var a={0}{1}{0};System.Console.Write(a,'{0}',a);}}}}";System.Con‌​sole.Write(a,'"',a);‌​}}

Basic quine, just contains a self-containing string.

LegionMammal978

Posted 2011-01-28T00:34:05.293

Reputation: 14 318

More shorter version (149 bytes): class A{static void Main(){var a="class A{{static void Main(){{var a={0}{1}{0};System.Console.Write(a,'{0}',a);}}}}";System.Console.Write(a,'"',a);}} – Ivan Kochurkin – 2016-09-15T11:19:44.787

2

DUP, 51 bytes

0"0.[34,0[$;$][,1+]#]$!%%!"0.[34,0[$;$][,1+]#]$!%%!

Try it here.

Well, DUP quines are possible, just really, really, long. I'll have to golf some more.

Mama Fun Roll

Posted 2011-01-28T00:34:05.293

Reputation: 6 535

2

reticular, 9 bytes

"'34'coo;

This captures the string '34'coo;, then wraps around. After that, the number 34 is pushed the stack, converted to a character with c, finally being outputted with o. The next o outputs the captured string, and ; terminates the program.

Other quines:

"'34'c~O;
"6@P2*c~O;

Conor O'Brien

Posted 2011-01-28T00:34:05.293

Reputation: 25 859

2

Python 2 and 3 - 32 bytes

s='s=%r;print(s%%s)';print(s%s)

From Ray Toal's Quine Page

ceilingcat

Posted 2011-01-28T00:34:05.293

Reputation: 2 384

2

Jelly, 6 bytes

There are two proper and payload capable "built-in" quines of 6-bytes:

“ØV”ṘV - takes no input
“ØV”   - make the string “ØV”
    Ṙ  - print and yield left (prints “ØV”, yields “ØV”)
     V - eval Jelly code (the code ØV yields the string “ṘV”)
       - implicit return of the string “ṘV”, so the final output is “ØV”ṘV

and

“Øv”Ṙv - as above,  except:
         v evals with an input, which in this case is empty; and
         Øv yields “Ṙv”

A payload may be placed directly after the leading open quote in either.

Jonathan Allan

Posted 2011-01-28T00:34:05.293

Reputation: 41 064

2

Straw, 10 bytes (non-competing)

(:%>>):%>>

TuxCopter

Posted 2011-01-28T00:34:05.293

Reputation: 3 661

2

J 4 bytes

I know this competition is probably dead but I wanted to put my answer in.

Just found this by accident

1 b.

J 1 bytes

0

XiKuuKy

Posted 2011-01-28T00:34:05.293

Reputation: 359

1Nice... I think you found the shortest possible quine once again! – Erik the Outgolfer – 2016-09-14T13:32:14.040

3These basically rely on the repl state of J, and are rather trivial. But, if it's happening like this, 1&amp; is shorter than 1 b.. – Conor O'Brien – 2016-10-14T22:58:01.240

2

PowerShell, 41 37 Bytes:

function q{"function q{$function:q};q"};q

filter q{"filter q{$function:q};q"};q

Thanks to TimmyD for saving 4 bytes

Chad Baxter

Posted 2011-01-28T00:34:05.293

Reputation: 228

What interpreter / compiler does this work in? In this interpreter, this submission doesn't work (it outputs function q{End: { "function q{$function:q};q" }};q).

– Loovjo – 2016-10-06T18:00:23.003

@Loovjo Most online PowerShell interpreters use an open-source PoSH that's roughly equivalent to PowerShell v0.5 and lacking many features. The above works fine in an actual install on Windows. – AdmBorkBork – 2016-10-07T13:08:34.603

At least in v4 on Windows 8.1, you can shave a few bytes using filter as follows -- filter q{"filter q{$function:q};q"};q for 37. – AdmBorkBork – 2016-10-07T13:09:27.170

$MyInvocation.MyCommand.ScriptBlock is 2 bytes shorter but almost definitely cheating? – ConnorLSW – 2017-02-22T22:38:10.963

2

Rust, 173 158 152 144 137 102 bytes

Tuples plus Rust's debug printing mechanism ( {:?} in a format string ) let me cut it down 30+ characters!

fn main(){let t=("fn main(){let t=", ";print!(\"{}{:?}{}\",t.0,t,t.1)}");print!("{}{:?}{}",t.0,t,t.1)}

Pretty-printed. It's so small there's little left to explain!

fn main() {
    // The space after the comma is necessary, because that's how
    // debug-print formats tuples
    let t=("fn main(){let t=", ";print!(\"{}{:?}{}\",t.0,t,t.1)}");
    print!("{}{:?}{}",t.0,t,t.1)
}

Harald Korneliussen

Posted 2011-01-28T00:34:05.293

Reputation: 340

1

Zetaplex, 13 bytes

"Sr34SZOsDrFe

Zetaplex is a variant of gammaplex. In it, commands are pairs of chars and act on an infinite stack.

Riker

Posted 2011-01-28T00:34:05.293

Reputation: 5 743

1

stacked, 16 bytes

Try it here!

[put ':!' put]:!

[put ':!' put] is a func, which is pushed to the stack. : duplicates it, and ! executes it, which prints the function, then :!.

Conor O'Brien

Posted 2011-01-28T00:34:05.293

Reputation: 25 859

1

memes, 2 bytes non-competing

The 3 is irrelevant, as in, any digit apart from 0 could be used. Non-competing as this language was made far after the challenge.

-3

Any mathematical token followed by a digit without anything infront will get interpreted as 0+x, as an example. Therefore -3 will result in 0-3, which returns -3.

devRicher

Posted 2011-01-28T00:34:05.293

Reputation: 1 269

Note simply 3 works too, but that is too much of an obvious reading-from-the-source. – devRicher – 2016-12-26T22:33:22.587

1

R, 47 bytes

f=function(){cat('f=');print(f);cat('f()')}
f()

Try it online!

Can be extended to contain any set of operations by adding those before the first cat statement.

Printing a function f returns the content of that function starting with function(){. I then added cat statements to handle the rest of the output.

JAD

Posted 2011-01-28T00:34:05.293

Reputation: 2 185

should probably be 53 bytes, as print will add indentation and weird brackets placement.

– Giuseppe – 2018-01-25T15:41:47.740

@Giuseppe hmm, on TIO there also appears to be trailing spaces. If counting those we'd end up at 64 bytes – JAD – 2018-01-25T16:36:38.487

1

DipDup, non-competing, 6 bytes

[_:]_:

Try it online!

Explanation

[_:]        push this list
    _       duplicate
     :      cons

alephalpha

Posted 2011-01-28T00:34:05.293

Reputation: 18 628

1

Racket, 90 bytes

((lambda (x) (display (list (~a x) (~v x)))) '(lambda (x) (display (list (~a x) (~v x)))))

Matthew Butterick

Posted 2011-01-28T00:34:05.293

Reputation: 386

You can remove unnecessary spaces to golf bytes. I'm not sure what spaces you can remove (cause I use Clojure), but there's definitely spaces that you can remove. – Qwerp-Derp – 2017-01-23T09:37:54.733

Not in this case, because the input has to match the printed output – Matthew Butterick – 2017-01-23T13:12:57.703

Oh... yeah, whoops. I'm just looking at the spaces and thinking that they can be golfed somehow. Well, TIL. – Qwerp-Derp – 2017-01-23T22:00:51.347

1

Pip, 15 bytes

V Y"`V Y`.RPy"

The code includes a trailing newline. Try it online!

Explanation

  Y"..."  Yank this string into the y variable
V         and evaluate it

which executes this:

`V Y`      A Pattern literal (for our purposes, a string-like object without "")
     .     to which we concatenate
      RPy  repr(y), which wraps y in ""

The result is autoprinted with a trailing newline.

Bonus submission, 18 bytes

The above is the shortest Pip quine that I've found, but unfortunately it doesn't do so well when you try to modify it for other quine challenges. I have found this one to be more payload-friendly:

Y"Y yRsRPy"yRsRPy

Y"Y yRsRPy"        Yank that string into y
           yRsRPy  Take y and replace space with repr(y)

DLosc

Posted 2011-01-28T00:34:05.293

Reputation: 17 064

1

SmileBASIC, 66 bytes

P$="+CHR$(34)?RIGHT$(P$,4);P$*2P$="+CHR$(34)?RIGHT$(P$,4);P$*2P$="

Modified version of a program taken from https://www.nyx.net/~gthompso/self_bas.txt

12Me21

Posted 2011-01-28T00:34:05.293

Reputation: 3 806

1

AWK, 72 bytes

BEGIN{s="BEGIN{s=%c%s%c;printf s,34,s,34}";printf s,34,s,34}

In 6 years nobody had written an AWK solution :(


This can be run from command-line as:

awk 'BEGIN{s="BEGIN{s=%c%s%c;printf s,34,s,34}";printf s,34,s,34}'

or placed in a file, FILE and run as:

awk -f FILE

Note: no newline is printed so if storing in a file... the file shouldn't have an EOF in it... maybe? We can add an EOF by adding print statements but that adds 12 bytes. This happens to be my first ever quine. :) It took me a bit to figure out how to get the quotation marks, since I first wanted to use \" but I'd have to escape the \ and then escape that one... ASCII to the rescue :)

Robert Benson

Posted 2011-01-28T00:34:05.293

Reputation: 1 259

After I posted this I was curious if there was an extant AWK quine example. Apparently so at https://www.nyx.net/~gthompso/self_awk.txt. Given that, I believe this might be the shortest possible AWK quine.

– Robert Benson – 2017-02-23T21:07:35.727

1

k, 48 bytes

This is, of course, ignoring the trivial quines, such as () or 1.

{}`0:(`c$34)/{(x;x;())}"{}`0:(`c$34)/{(x;x;())}"

Try it out.

zgrep

Posted 2011-01-28T00:34:05.293

Reputation: 841

1

Tcl, 61 chars

set c {set c {$c};puts [subst -noc \$c]};puts [subst -noc $c]

Johannes Kuhn

Posted 2011-01-28T00:34:05.293

Reputation: 6 582

1

Scala, 540 Bytes

object Q {
  def main(a:Array[String]):Unit={
    val d=Seq(
      "object Q {",
      "def main(a:Array[String]):Unit={",
      "val d=Seq(",
      "val c=println(_:String)",
      "val b=(x:Int)=>x.toChar.toString",
      "d take 3 map c",
      "val a=d.zipWithIndex.map(x=>b(34)+x._1+b(34)+(if(x._2==d.size-1)b(9).drop(1)else b(44)))",
      "a.map(c)",
      "c(b(41))",
      "d.drop(3).map(c)",
      "c(b(125))",
      "c(b(125))"
    )
    val c=println(_:String)
    val b=(x:Int)=>x.toChar.toString
    d take 3 map c
    val a=d.zipWithIndex.map(x=>b(34)+x._1+b(34)+(if(x._2==d.size-1)b(9).drop(1)else b(44)))
    a.map(c)
    c(b(41))
    d.drop(3).map(c)
    c(b(125))
    c(b(125))
  }
}

Can probably be improved. I decided to call it quits for now as it is 5 in the morning. I think something that can be changed to make this smaller is to encode the d value in some other way other than a sequence of strings. I haven't thought of a cool way to do it yet, though. This would also add to the obfuscation part of the challenge.

Stefan Aleksić

Posted 2011-01-28T00:34:05.293

Reputation: 109

1

Erlang escript 225 164 140

$ escript quine

main(_)->[A|B]=["main(_)->[A|B]=[","],io:put_chars([10,A,34,A,34,44,34,B,34,B,10,10])."],io:put_chars([10,A,34,A,34,44,34,B,34,B,10,10]).

$

Apparently escript has to have at least three lines.

Hynek -Pichi- Vychodil

Posted 2011-01-28T00:34:05.293

Reputation: 330

1

PowerShell, 24 bytes, 21 characters

.($s={".(`$s={$s})"})

I'm going to attempt to explain this, but be forewarned that I'm terrible at explaining myself.

This code sets $s to the following:

".(`$s={$s})"

This recursively sets the variable $s (the first $s is a plain string, but the second $s is the variable $s) in itself and then the block inside parentheses echoes $s, which at time of execution will be the following:

.($s={".(`$s={$s})"})`

wubs

Posted 2011-01-28T00:34:05.293

Reputation: 173

1

Hack 60 bytes

<?hh printf($p='<?hh printf($p=%c%s%c,39,$p,39);',39,$p,39);

Only language I could think to do it in that I didn't see on the list.

Mayube

Posted 2011-01-28T00:34:05.293

Reputation: 4 938

1

Brainfuck, 404 bytes

->++>+++>+>+>+++>>>>>>>>>>>>>>>>>>>>>>+>+>++>+++>++>>+++>+>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>+>+>>+++>>>>+++>>>+++>+>>>>>>>++>+++>+++>+>>+++>+++>+>+++>+>+++>+>++>+++>>>+>+>+>+>++>+++>+>+>>+++>>>>>>>+>+>>>+>+>++>+++>+++>+>>+++>+++>+>+++>+>++>+++>++>>+>+>++>+++>+>+>>+++>>>+++>+>>>++>+++>+++>+>>+++>>>+++>+>+++>+>>+++>>+++>>+[[>>+[>]+>+[<]<-]>>[>]<+<+++[<]<<+]>>>[>]+++>+[+[<++++++++++++++++>-]<++++++++++.<]

Try it online!

I found this quine here; I didn't write it myself. I'm currently trying to understand how it works exactly to add an explanation.

Luke

Posted 2011-01-28T00:34:05.293

Reputation: 4 365

1

Forth, 105 bytes

S" 2dup 34 83 emit emit space type 34 emit space type" 2dup 34 83 emit emit space type 34 emit space type

Try it online

Explanation:

S" 2dup 34 83 emit emit space type 34 emit space type"      \ push a string
   2dup                                                     \ duplicate string
        34 83 emit emit space                               \ print 'S" '
                              type                          \ print string
                                   34 emit space            \ print '" '
                                                 type       \ print string duplicate

mbomb007

Posted 2011-01-28T00:34:05.293

Reputation: 16 876

1

Standard ML (MLton), 60 bytes

";str(chr 34)^it;print(it^it);";str(chr 34)^it;print(it^it);

Try it online!

I previously thought this kind of quine would only work when interpreted, e.g. by the Moscow ML interpreter. However, MLton happily compiles it to a standalone executable, so I guess it's fine.

How it works

Usually one writes val x = <some expression> ; in a SML interpreter to bind the identifier x to result of the evaluation of <some expression>. If the val x = part is omitted, the result is bound to the implicit result identifier it instead.

The quine consists of three declarations:

";str(chr 34)^it;print(it^it);";

A single string, so it = ";str(chr 34)^it;print(it^it);".

str(chr 34)^it;

chr 34 yields the 34th ASCII-character, which is ". str converts the character into a string and the ^-operator performs string concatenation, thus it = "\";str(chr 34)^it;print(it^it);".

print(it^it);

it^it now yields an escaped string version of the source code which is printed to STDOUT with print.

Laikoni

Posted 2011-01-28T00:34:05.293

Reputation: 15 037

1

x86/DOS assembly, 4619 bytes

bits 16
org 256
mov ah,64
mov bx,1
mov cx,720
mov dx,b+16
int 33
mov cx,90
mov si,b+16
c:push cx
mov ah,64
mov bx,1
mov cx,6
mov dx,b
int 33
mov cx,7
a:push cx
mov al,[si]
shr al,4
add al,48
cmp al,58
jb g
add al,39
g:mov [b+8],al
lodsb
and al,15
add al,48
cmp al,58
jb e
add al,39
e:mov [b+9],al
mov ah,64
mov bx,1
mov cx,5
mov dx,b+6
int 33
pop cx
loop a
mov al,[si]
shr al,4
add al,48
cmp al,58
jb h
add al,39
h:mov [b+8],al
lodsb
and al,15
add al,48
cmp al,58
jb n
add al,39
n:mov [b+9],al
mov ah,64
mov bx,1
mov cx,4
mov dx,b+6
int 33
pop cx
loop c
mov ah,64
mov bx,1
mov cx,5
mov dx,b+11
int 33
mov ah,76
int 33
b   db 13,10,' db 0x  ,',13,10,'end'
 db 0x62,0x69,0x74,0x73,0x20,0x31,0x36,0x0d
 db 0x0a,0x6f,0x72,0x67,0x20,0x32,0x35,0x36
 db 0x0d,0x0a,0x6d,0x6f,0x76,0x20,0x61,0x68
 db 0x2c,0x36,0x34,0x0d,0x0a,0x6d,0x6f,0x76
 db 0x20,0x62,0x78,0x2c,0x31,0x0d,0x0a,0x6d
 db 0x6f,0x76,0x20,0x63,0x78,0x2c,0x37,0x32
 db 0x30,0x0d,0x0a,0x6d,0x6f,0x76,0x20,0x64
 db 0x78,0x2c,0x62,0x2b,0x31,0x36,0x0d,0x0a
 db 0x69,0x6e,0x74,0x20,0x33,0x33,0x0d,0x0a
 db 0x6d,0x6f,0x76,0x20,0x63,0x78,0x2c,0x39
 db 0x30,0x0d,0x0a,0x6d,0x6f,0x76,0x20,0x73
 db 0x69,0x2c,0x62,0x2b,0x31,0x36,0x0d,0x0a
 db 0x63,0x3a,0x70,0x75,0x73,0x68,0x20,0x63
 db 0x78,0x0d,0x0a,0x6d,0x6f,0x76,0x20,0x61
 db 0x68,0x2c,0x36,0x34,0x0d,0x0a,0x6d,0x6f
 db 0x76,0x20,0x62,0x78,0x2c,0x31,0x0d,0x0a
 db 0x6d,0x6f,0x76,0x20,0x63,0x78,0x2c,0x36
 db 0x0d,0x0a,0x6d,0x6f,0x76,0x20,0x64,0x78
 db 0x2c,0x62,0x0d,0x0a,0x69,0x6e,0x74,0x20
 db 0x33,0x33,0x0d,0x0a,0x6d,0x6f,0x76,0x20
 db 0x63,0x78,0x2c,0x37,0x0d,0x0a,0x61,0x3a
 db 0x70,0x75,0x73,0x68,0x20,0x63,0x78,0x0d
 db 0x0a,0x6d,0x6f,0x76,0x20,0x61,0x6c,0x2c
 db 0x5b,0x73,0x69,0x5d,0x0d,0x0a,0x73,0x68
 db 0x72,0x20,0x61,0x6c,0x2c,0x34,0x0d,0x0a
 db 0x61,0x64,0x64,0x20,0x61,0x6c,0x2c,0x34
 db 0x38,0x0d,0x0a,0x63,0x6d,0x70,0x20,0x61
 db 0x6c,0x2c,0x35,0x38,0x0d,0x0a,0x6a,0x62
 db 0x20,0x67,0x0d,0x0a,0x61,0x64,0x64,0x20
 db 0x61,0x6c,0x2c,0x33,0x39,0x0d,0x0a,0x67
 db 0x3a,0x6d,0x6f,0x76,0x20,0x5b,0x62,0x2b
 db 0x38,0x5d,0x2c,0x61,0x6c,0x0d,0x0a,0x6c
 db 0x6f,0x64,0x73,0x62,0x0d,0x0a,0x61,0x6e
 db 0x64,0x20,0x61,0x6c,0x2c,0x31,0x35,0x0d
 db 0x0a,0x61,0x64,0x64,0x20,0x61,0x6c,0x2c
 db 0x34,0x38,0x0d,0x0a,0x63,0x6d,0x70,0x20
 db 0x61,0x6c,0x2c,0x35,0x38,0x0d,0x0a,0x6a
 db 0x62,0x20,0x65,0x0d,0x0a,0x61,0x64,0x64
 db 0x20,0x61,0x6c,0x2c,0x33,0x39,0x0d,0x0a
 db 0x65,0x3a,0x6d,0x6f,0x76,0x20,0x5b,0x62
 db 0x2b,0x39,0x5d,0x2c,0x61,0x6c,0x0d,0x0a
 db 0x6d,0x6f,0x76,0x20,0x61,0x68,0x2c,0x36
 db 0x34,0x0d,0x0a,0x6d,0x6f,0x76,0x20,0x62
 db 0x78,0x2c,0x31,0x0d,0x0a,0x6d,0x6f,0x76
 db 0x20,0x63,0x78,0x2c,0x35,0x0d,0x0a,0x6d
 db 0x6f,0x76,0x20,0x64,0x78,0x2c,0x62,0x2b
 db 0x36,0x0d,0x0a,0x69,0x6e,0x74,0x20,0x33
 db 0x33,0x0d,0x0a,0x70,0x6f,0x70,0x20,0x63
 db 0x78,0x0d,0x0a,0x6c,0x6f,0x6f,0x70,0x20
 db 0x61,0x0d,0x0a,0x6d,0x6f,0x76,0x20,0x61
 db 0x6c,0x2c,0x5b,0x73,0x69,0x5d,0x0d,0x0a
 db 0x73,0x68,0x72,0x20,0x61,0x6c,0x2c,0x34
 db 0x0d,0x0a,0x61,0x64,0x64,0x20,0x61,0x6c
 db 0x2c,0x34,0x38,0x0d,0x0a,0x63,0x6d,0x70
 db 0x20,0x61,0x6c,0x2c,0x35,0x38,0x0d,0x0a
 db 0x6a,0x62,0x20,0x68,0x0d,0x0a,0x61,0x64
 db 0x64,0x20,0x61,0x6c,0x2c,0x33,0x39,0x0d
 db 0x0a,0x68,0x3a,0x6d,0x6f,0x76,0x20,0x5b
 db 0x62,0x2b,0x38,0x5d,0x2c,0x61,0x6c,0x0d
 db 0x0a,0x6c,0x6f,0x64,0x73,0x62,0x0d,0x0a
 db 0x61,0x6e,0x64,0x20,0x61,0x6c,0x2c,0x31
 db 0x35,0x0d,0x0a,0x61,0x64,0x64,0x20,0x61
 db 0x6c,0x2c,0x34,0x38,0x0d,0x0a,0x63,0x6d
 db 0x70,0x20,0x61,0x6c,0x2c,0x35,0x38,0x0d
 db 0x0a,0x6a,0x62,0x20,0x6e,0x0d,0x0a,0x61
 db 0x64,0x64,0x20,0x61,0x6c,0x2c,0x33,0x39
 db 0x0d,0x0a,0x6e,0x3a,0x6d,0x6f,0x76,0x20
 db 0x5b,0x62,0x2b,0x39,0x5d,0x2c,0x61,0x6c
 db 0x0d,0x0a,0x6d,0x6f,0x76,0x20,0x61,0x68
 db 0x2c,0x36,0x34,0x0d,0x0a,0x6d,0x6f,0x76
 db 0x20,0x62,0x78,0x2c,0x31,0x0d,0x0a,0x6d
 db 0x6f,0x76,0x20,0x63,0x78,0x2c,0x34,0x0d
 db 0x0a,0x6d,0x6f,0x76,0x20,0x64,0x78,0x2c
 db 0x62,0x2b,0x36,0x0d,0x0a,0x69,0x6e,0x74
 db 0x20,0x33,0x33,0x0d,0x0a,0x70,0x6f,0x70
 db 0x20,0x63,0x78,0x0d,0x0a,0x6c,0x6f,0x6f
 db 0x70,0x20,0x63,0x0d,0x0a,0x6d,0x6f,0x76
 db 0x20,0x61,0x68,0x2c,0x36,0x34,0x0d,0x0a
 db 0x6d,0x6f,0x76,0x20,0x62,0x78,0x2c,0x31
 db 0x0d,0x0a,0x6d,0x6f,0x76,0x20,0x63,0x78
 db 0x2c,0x35,0x0d,0x0a,0x6d,0x6f,0x76,0x20
 db 0x64,0x78,0x2c,0x62,0x2b,0x31,0x31,0x0d
 db 0x0a,0x69,0x6e,0x74,0x20,0x33,0x33,0x0d
 db 0x0a,0x6d,0x6f,0x76,0x20,0x61,0x68,0x2c
 db 0x37,0x36,0x0d,0x0a,0x69,0x6e,0x74,0x20
 db 0x33,0x33,0x0d,0x0a,0x62,0x20,0x20,0x20
 db 0x64,0x62,0x20,0x31,0x33,0x2c,0x31,0x30
 db 0x2c,0x27,0x20,0x64,0x62,0x20,0x30,0x78
 db 0x20,0x20,0x2c,0x27,0x2c,0x31,0x33,0x2c
 db 0x31,0x30,0x2c,0x27,0x65,0x6e,0x64,0x27
end

MD XF

Posted 2011-01-28T00:34:05.293

Reputation: 8 337

1

80x86 TASM, 561 bytes

MODEL TINY
.CODE
.STARTUP
DB 177
DB 076
DB 186
DB 044
DB 001
DB 172
DB 180
DB 036
DB 179
DB 004
DB 191
DB 080
DB 001
DB 079
DB 136
DB 037
DB 212
DB 010
DB 004
DB 048
DB 134
DB 196
DB 075
DB 117
DB 244
DB 180
DB 009
DB 205
DB 033
DB 178
DB 071
DB 226
DB 228
DB 178
DB 038
DB 205
DB 033
DB 195
DB 013
DB 010
DB 069
DB 078
DB 068
DB 036
DB 077
DB 079
DB 068
DB 069
DB 076
DB 032
DB 084
DB 073
DB 078
DB 089
DB 013
DB 010
DB 046
DB 067
DB 079
DB 068
DB 069
DB 013
DB 010
DB 046
DB 083
DB 084
DB 065
DB 082
DB 084
DB 085
DB 080
DB 013
DB 010
DB 068
DB 066
DB 032
END

MD XF

Posted 2011-01-28T00:34:05.293

Reputation: 8 337

@Downvoter I can kind of understand the downvotes on all the quines I posted from RosettaCode, but this one, really? – MD XF – 2017-05-25T17:23:44.813

1

shortC, 38 28 bytes

AR_="AR_=%c%s%1$c,34,_",34,_

Try it online!

MD XF

Posted 2011-01-28T00:34:05.293

Reputation: 8 337

1

ABAP, 515 bytes

REPORT R NO STANDARD PAGE HEADING.DATA:A TYPE TABLE OF STRING,B(8).APPEND:
`REPORT.FORM F TABLES T.NEW-PAGE LINE-SIZE 78.WRITE:'REPORT R NO',` TO A,
`'STANDARD PAGE HEADING.DATA:A TYPE TABLE OF STRING,B(8).APPEND:'.LOOP` TO A,
`AT T.REPLACE ALL OCCURENCES OF'``' IN T WITH'````'.WRITE:/'``'` TO A,
`NO-GAP,T NO-GAP,'`` TO A,'.ENDLOOP.WRITE:AT 78'.','GENERATE',` TO A,
`'SUBROUTINE POOL A NAME B.PERFORM F IN PROGRAM (B) TABLES A.'.ENDFORM.` TO A.
GENERATE SUBROUTINE POOL A NAME B.PERFORM F IN PROGRAM (B) TABLES A.

Should work on on any SAP system with SY-SAPRL >= '700'.

source

MD XF

Posted 2011-01-28T00:34:05.293

Reputation: 8 337

is this an error quine? – Destructible Lemon – 2017-05-24T23:53:22.123

@DestructibleLemon No, why do you ask? – MD XF – 2017-05-25T00:46:19.537

Anyone care to explain the serial downvoting? – MD XF – 2017-05-25T17:20:35.533

1

Bob, 1221 bytes

c=","; n="\n"; q="\""; s="\\";
v=\[
"c=\",\"; n=\"\\n\"; q=\"\\\"\"; s=\"\\\\\";",
"v=\\[",
"define prtQuote(str) {",
" local j,t,v;",
" stdout.Display(q);",
" for (j=0; j<str.size; j++) {",
"  t = str.Substring(j,1);",
"  if (t==q) { stdout.Display(s); }",
"  if (t==s) { stdout.Display(s); }",
"  stdout.Display(t);",
" }",
" stdout.Display(q);",
"}",
"for(i=0; i<2; i++){ stdout.Display(v[i]); stdout.Display(n); }",
"for(i=0; i<v.size-1; i++){ prtQuote(v[i]); stdout.Display(c); stdout.Display(n); }",
"prtQuote(v[v.size-1]); stdout.Display(n);",
"stdout.Display(v[v.size-1]); stdout.Display(n);",
"for(i=2; i<v.size-1; i++){ stdout.Display(v[i]); stdout.Display(n); }",
"];"
];
define prtQuote(str) {
 local j,t,v;
 stdout.Display(q);
 for (j=0; j<str.size; j++) {
  t = str.Substring(j,1);
  if (t==q) { stdout.Display(s); }
  if (t==s) { stdout.Display(s); }
  stdout.Display(t);
 }
 stdout.Display(q);
}
for(i=0; i<2; i++){ stdout.Display(v[i]); stdout.Display(n); }
for(i=0; i<v.size-1; i++){ prtQuote(v[i]); stdout.Display(c); stdout.Display(n); }
prtQuote(v[v.size-1]); stdout.Display(n);
stdout.Display(v[v.size-1]); stdout.Display(n);
for(i=2; i<v.size-1; i++){ stdout.Display(v[i]); stdout.Display(n); }

source

MD XF

Posted 2011-01-28T00:34:05.293

Reputation: 8 337

1

COBOL, 18808 bytes

This was posted to the mvsHelp forum in 2004. Spaces necessary.

       IDENTIFICATION DIVISION.
       PROGRAM-ID. GRICE.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SPECIAL-NAMES.
           SYMBOLIC CHARACTERS FULL-STOP IS 76.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT OUTPUT-FILE ASSIGN TO OUTPUT1.
       DATA DIVISION.
       FILE SECTION.
       FD  OUTPUT-FILE
           RECORDING MODE F
           LABEL RECORDS OMITTED.
       01  OUTPUT-RECORD                     PIC X(80).
       WORKING-STORAGE SECTION.
       01  SUB-X                             PIC S9(4) COMP.
       01  SOURCE-FACSIMILE-AREA.
           02  SOURCE-FACSIMILE-DATA.
               03  FILLER                    PIC X(40) VALUE
               "       IDENTIFICATION DIVISION.         ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "       PROGRAM-ID. GRICE.               ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "       ENVIRONMENT DIVISION.            ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "       CONFIGURATION SECTION.           ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "       SPECIAL-NAMES.                   ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "           SYMBOLIC CHARACTERS FULL-STOP".
               03  FILLER                    PIC X(40) VALUE
               " IS 76.                                 ".
               03  FILLER                    PIC X(40) VALUE
               "       INPUT-OUTPUT SECTION.            ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "       FILE-CONTROL.                    ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "           SELECT OUTPUT-FILE ASSIGN TO ".
               03  FILLER                    PIC X(40) VALUE
               "OUTPUT1.                                ".
               03  FILLER                    PIC X(40) VALUE
               "       DATA DIVISION.                   ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "       FILE SECTION.                    ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "       FD  OUTPUT-FILE                  ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "           RECORDING MODE F             ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "           LABEL RECORDS OMITTED.       ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "       01  OUTPUT-RECORD                ".
               03  FILLER                    PIC X(40) VALUE
               "     PIC X(80).                         ".
               03  FILLER                    PIC X(40) VALUE
               "       WORKING-STORAGE SECTION.         ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "       01  SUB-X                        ".
               03  FILLER                    PIC X(40) VALUE
               "     PIC S9(4) COMP.                    ".
               03  FILLER                    PIC X(40) VALUE
               "       01  SOURCE-FACSIMILE-AREA.       ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "           02  SOURCE-FACSIMILE-DATA.   ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "               03  FILLER               ".
               03  FILLER                    PIC X(40) VALUE
               "     PIC X(40) VALUE                    ".
               03  FILLER                    PIC X(40) VALUE
               "           02  SOURCE-FACSIMILE-TABLE RE".
               03  FILLER                    PIC X(40) VALUE
               "DEFINES                                 ".
               03  FILLER                    PIC X(40) VALUE
               "                   SOURCE-FACSIMILE-DATA".
               03  FILLER                    PIC X(40) VALUE
               ".                                       ".
               03  FILLER                    PIC X(40) VALUE
               "               03  SOURCE-FACSIMILE OCCU".
               03  FILLER                    PIC X(40) VALUE
               "RS 68.                                  ".
               03  FILLER                    PIC X(40) VALUE
               "                   04  SOURCE-FACSIMILE-".
               03  FILLER                    PIC X(40) VALUE
               "ONE  PIC X(40).                         ".
               03  FILLER                    PIC X(40) VALUE
               "                   04  SOURCE-FACSIMILE-".
               03  FILLER                    PIC X(40) VALUE
               "TWO  PIC X(40).                         ".
               03  FILLER                    PIC X(40) VALUE
               "       01  FILLER-IMAGE.                ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "           02  FILLER                   ".
               03  FILLER                    PIC X(40) VALUE
               "     PIC X(15) VALUE SPACES.            ".
               03  FILLER                    PIC X(40) VALUE
               "           02  FILLER                   ".
               03  FILLER                    PIC X(40) VALUE
               "     PIC X     VALUE QUOTE.             ".
               03  FILLER                    PIC X(40) VALUE
               "           02  FILLER-DATA              ".
               03  FILLER                    PIC X(40) VALUE
               "     PIC X(40).                         ".
               03  FILLER                    PIC X(40) VALUE
               "           02  FILLER                   ".
               03  FILLER                    PIC X(40) VALUE
               "     PIC X     VALUE QUOTE.             ".
               03  FILLER                    PIC X(40) VALUE
               "           02  FILLER                   ".
               03  FILLER                    PIC X(40) VALUE
               "     PIC X     VALUE FULL-STOP.         ".
               03  FILLER                    PIC X(40) VALUE
               "           02  FILLER                   ".
               03  FILLER                    PIC X(40) VALUE
               "     PIC X(22) VALUE SPACES.            ".
               03  FILLER                    PIC X(40) VALUE
               "       PROCEDURE DIVISION.              ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "       MAIN-LINE SECTION.               ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "       ML-1.                            ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "           OPEN OUTPUT OUTPUT-FILE.     ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "           MOVE 1 TO SUB-X.             ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "       ML-2.                            ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "           MOVE SOURCE-FACSIMILE (SUB-X)".
               03  FILLER                    PIC X(40) VALUE
               " TO OUTPUT-RECORD.                      ".
               03  FILLER                    PIC X(40) VALUE
               "           WRITE OUTPUT-RECORD.         ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "           IF  SUB-X < 19               ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "               ADD 1 TO SUB-X           ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "               GO TO ML-2.              ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "           MOVE 1 TO SUB-X.             ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "       ML-3.                            ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "           MOVE SOURCE-FACSIMILE (20) TO".
               03  FILLER                    PIC X(40) VALUE
               " OUTPUT-RECORD.                         ".
               03  FILLER                    PIC X(40) VALUE
               "           WRITE OUTPUT-RECORD.         ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "           MOVE SOURCE-FACSIMILE-ONE (SU".
               03  FILLER                    PIC X(40) VALUE
               "B-X) TO FILLER-DATA.                    ".
               03  FILLER                    PIC X(40) VALUE
               "           MOVE FILLER-IMAGE TO OUTPUT-R".
               03  FILLER                    PIC X(40) VALUE
               "ECORD.                                  ".
               03  FILLER                    PIC X(40) VALUE
               "           WRITE OUTPUT-RECORD.         ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "           MOVE SOURCE-FACSIMILE (20) TO".
               03  FILLER                    PIC X(40) VALUE
               " OUTPUT-RECORD.                         ".
               03  FILLER                    PIC X(40) VALUE
               "           WRITE OUTPUT-RECORD.         ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "           MOVE SOURCE-FACSIMILE-TWO (SU".
               03  FILLER                    PIC X(40) VALUE
               "B-X) TO FILLER-DATA.                    ".
               03  FILLER                    PIC X(40) VALUE
               "           MOVE FILLER-IMAGE TO OUTPUT-R".
               03  FILLER                    PIC X(40) VALUE
               "ECORD.                                  ".
               03  FILLER                    PIC X(40) VALUE
               "           WRITE OUTPUT-RECORD.         ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "           IF  SUB-X < 68               ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "               ADD 1 TO SUB-X           ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "               GO TO ML-3.              ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "           MOVE 21 TO SUB-X.            ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "       ML-4.                            ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "           MOVE SOURCE-FACSIMILE (SUB-X)".
               03  FILLER                    PIC X(40) VALUE
               " TO OUTPUT-RECORD.                      ".
               03  FILLER                    PIC X(40) VALUE
               "           WRITE OUTPUT-RECORD.         ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "           IF  SUB-X < 68               ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "               ADD 1 TO SUB-X           ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "               GO TO ML-4.              ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "       ML-99.                           ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "           CLOSE OUTPUT-FILE.           ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
               03  FILLER                    PIC X(40) VALUE
               "           STOP RUN.                    ".
               03  FILLER                    PIC X(40) VALUE
               "                                        ".
           02  SOURCE-FACSIMILE-TABLE REDEFINES
                   SOURCE-FACSIMILE-DATA.
               03  SOURCE-FACSIMILE OCCURS 68.
                   04  SOURCE-FACSIMILE-ONE  PIC X(40).
                   04  SOURCE-FACSIMILE-TWO  PIC X(40).
       01  FILLER-IMAGE.
           02  FILLER                        PIC X(15) VALUE SPACES.
           02  FILLER                        PIC X     VALUE QUOTE.
           02  FILLER-DATA                   PIC X(40).
           02  FILLER                        PIC X     VALUE QUOTE.
           02  FILLER                        PIC X     VALUE FULL-STOP.
           02  FILLER                        PIC X(22) VALUE SPACES.
       PROCEDURE DIVISION.
       MAIN-LINE SECTION.
       ML-1.
           OPEN OUTPUT OUTPUT-FILE.
           MOVE 1 TO SUB-X.
       ML-2.
           MOVE SOURCE-FACSIMILE (SUB-X) TO OUTPUT-RECORD.
           WRITE OUTPUT-RECORD.
           IF  SUB-X < 19
               ADD 1 TO SUB-X
               GO TO ML-2.
           MOVE 1 TO SUB-X.
       ML-3.
           MOVE SOURCE-FACSIMILE (20) TO OUTPUT-RECORD.
           WRITE OUTPUT-RECORD.
           MOVE SOURCE-FACSIMILE-ONE (SUB-X) TO FILLER-DATA.
           MOVE FILLER-IMAGE TO OUTPUT-RECORD.
           WRITE OUTPUT-RECORD.
           MOVE SOURCE-FACSIMILE (20) TO OUTPUT-RECORD.
           WRITE OUTPUT-RECORD.
           MOVE SOURCE-FACSIMILE-TWO (SUB-X) TO FILLER-DATA.
           MOVE FILLER-IMAGE TO OUTPUT-RECORD.
           WRITE OUTPUT-RECORD.
           IF  SUB-X < 68
               ADD 1 TO SUB-X
               GO TO ML-3.
           MOVE 21 TO SUB-X.
       ML-4.
           MOVE SOURCE-FACSIMILE (SUB-X) TO OUTPUT-RECORD.
           WRITE OUTPUT-RECORD.
           IF  SUB-X < 68
               ADD 1 TO SUB-X
               GO TO ML-4.
       ML-99.
           CLOSE OUTPUT-FILE.
           STOP RUN.

MD XF

Posted 2011-01-28T00:34:05.293

Reputation: 8 337

1

Conway's Game of Life, 7 bytes

!
**
**

Uses Plaintext format.

MD XF

Posted 2011-01-28T00:34:05.293

Reputation: 8 337

5 bytes, you missed the newline. Alternatively, in Standard Plaintext: **\n** – CalculatorFeline – 2017-05-27T23:30:34.273

@CalculatorFeline Thanks, edited. – MD XF – 2017-05-28T00:23:22.527

What interpreter are you running this in? – Wheat Wizard – 2017-05-28T20:50:15.113

@WheatWizard This is not necessarily run in an interpreter, it simply means "a 2x2 square of live cells in an empty grid". – MD XF – 2017-05-28T21:16:40.530

Languages are defined by their interpreters, if you don't have an interpreter that can take this as a source file then you can't submit this to a challenge. – Wheat Wizard – 2017-05-28T21:28:50.453

@WheatWizard Fixed. – MD XF – 2017-05-28T21:47:22.957

@Riker Nope, that's talking about the final line. This is the initial line and AFAIK it's necessary. – MD XF – 2017-06-01T17:54:13.050

-1 this method of IO is very limited – ASCII-only – 2017-08-28T02:31:32.433

@ASCII-only since when do quines need input? – MD XF – 2017-08-29T22:57:52.783

Well this method of output mostly – ASCII-only – 2017-08-29T22:58:42.493

1

Vim, 27 bytes

ii^V^V^V^[BDuplxbbpp^[BDuplxbbpp

^V being CTRL+V and ^[ being ESC.

The other one is beating mine, but it took a while and I didn't think it was possible.

MD XF

Posted 2011-01-28T00:34:05.293

Reputation: 8 337

1

Bash, 54 52 bytes

-2 thanks to Ørjan Johansen

a=\' b='a=\\$a b=$a$b$a\;eval echo \$b';eval echo $b

MD XF

Posted 2011-01-28T00:34:05.293

Reputation: 8 337

The spaces after the semicolons seem unnecessary. – Ørjan Johansen – 2017-05-27T02:06:23.327

@ØrjanJohansen Oh, I completely forgot to golf that part! Thanks :D – MD XF – 2017-05-27T02:27:09.297

You forgot to include the new length. – Ørjan Johansen – 2017-05-27T02:39:59.707

@ØrjanJohansen Is there any limit to how helpful you can be :P – MD XF – 2017-05-27T02:40:45.533

1

Excel, 131 bytes

=SUBSTITUTE("=SUBSTITUTE(@,CHAR(64),CHAR(34)&@&CHAR(34))",CHAR(64),CHAR(34)&"=SUBSTITUTE(@,CHAR(64),CHAR(34)&@&CHAR(34))"&CHAR(34))

Adapted from a program by Dave Burt.

MD XF

Posted 2011-01-28T00:34:05.293

Reputation: 8 337

1

PHP, 50 chars

<?printf($s='<?printf($s=%c%s%1$c,39,$s);',39,$s);

I realized I could save four chars by enabling short tags (<?=sprintf becomes <?printf)

I saved four more bytes by reusing one of the values in my printf.

Umbrella

Posted 2011-01-28T00:34:05.293

Reputation: 296

1

Add++, 14 bytes

L,"L,%rd%%"d%

Try it online!

Takes advantage of Python string formatting with the % command.

caird coinheringaahing

Posted 2011-01-28T00:34:05.293

Reputation: 6 705

1

><>, 42 Bytes

'r3d*>l?\ao"/o \     "ooooooooo;
     \ o/

Try it online

Sasha

Posted 2011-01-28T00:34:05.293

Reputation: 91

1

RProgN 2, 3 bytes


«Ø

Try it online!

This code does nothing with the first line, then, pushes the function «Ø. As « is unmatched, it falls through and executes the contents. Ø then pushes an empty string. The implicit printing behaviour first prints the empty string, then the function, giving our source code.

4 bytes

«•. 

(With a leading space)

Try it online!

This uses the fall through behavoir of the last quine, but ensures "quine" behavoir a different way. pushes a space, . concatenates it, which gives our code.

6 bytes

{`{.}{

Try it online!

This uses a different fallthrough behavoir. {`{.} pushes a funciton, then {, with an unmatched }, fails and moves the IP back to index 1, which skips the function definition, and runs its contents instead. (backtick){ pushes { as a string, then . appends it to the function, stringifying it. } then terminates the program, and the string is implicitely output.

ATaco

Posted 2011-01-28T00:34:05.293

Reputation: 6 373

1

OML, 20 bytes

"lK(34Tos)"lK(34Tos)

Try it online!

This was an interesting process. I initially started off with the classic data-decoder method of quining. That is, one devotes one section of the program to encoding the decoder, and another section to generate the data representation and decode the data. This came out to look like this (51 bytes):

'\'l'K'l'2'/'['('''''o'o')']'('o')\lKl2/[(''oo)](o)

Where the data section looks like:

'\'l'K'l'2'/'['('''''o'o')']'('o')

which pushes each character after a '. The decoder looks like this:

\lKl2/[(''oo)](o)
\                  reverse stack
 lK                duplicate stack
   l2/[            copy the duplication into a new stack
       (    )      while there are characters on this stack:
        ''o          output a single quote
           o         and the character
             ]     return to the original stack
              (o)  output all characters on this stack

This can be improved slightly by replacing (o) with ls (48 bytes):

'\'l'K'l'2'/'['('''''o'o')']'l's\lKl2/[(''oo)]ls

However, OML also has a length-encoded string construct. Let's say the string is "xyz". This is effectively 'x'y'z3, since there are three characters in the string. We can use s to print this string, but we still need to generate the quote characters. With all this in mind, I was able to devise the following approach (26 bytes):

"lK34Tos34Tos"lK34Tos34Tos

Simply put, this puts the "string" "lK34Tos34Tos" to the stack, then performs the following actions:

lK34Tos34Tos
lk            duplicate the stack (in this case, the string)
  34To        output a quotation mark "
      s       output the string
       34To   output another quotation mark "
           s  output the string again

We obtain our final version by noting that the structure 34Tos is repeated twice. We can use a while loop to produce the current answer.

Conor O'Brien

Posted 2011-01-28T00:34:05.293

Reputation: 25 859

1

Befunge-93, 11 15 bytes

+:0#5g:!_#@,1#

(Plus a trailing newline)

Try It Online

How it works

 :        Duplicates counter
  0  g    Gets current char in program using counter
      :   Duplicates char
       !_ Checks if it is the end of the program
+:  5      @,    If so, create a newline character, print it and end program
+           ,1   If not, print the char and increment the counter and repeat

This version still reads its own source code, but has a part of it that encodes another part.

Previous version, 11 bytes

Crossed the line for PPCG's definition of a quine

:0g:!#@_,1+

Try It Online

Some might argue it's technically reading its own source code, but no more than the other Befunge quines.

:            Duplicates the counter
 0g          Gets the character at that point
   :!#@_     Ends the program if that character is empty
        ,    Prints the character
         1+  Increments the counter before looping back around to the start

Jo King

Posted 2011-01-28T00:34:05.293

Reputation: 5 911

This is most certainly reading its own source code, what other answers are you talking about (there are quite a few here so it is hard to navigate)? If this is truly reading its source code "no more than the other Befunge quines" they are invalid as well. – Wheat Wizard – 2017-12-06T06:16:57.700

@WheatWizard The previous Befunge Quine uses a string literal that wraps around and adds every character in the code to the stack. The Cubix quine uses a similar technique

– Jo King – 2017-12-06T06:56:56.440

Here is the most recent consensus on what makes a valid quine, as you might notice the old befunge quine meets this definition provided because &lt;@,*2+98_,#! #:&lt; encodes both itself (on the first pass) and " on the second. Your answer has every character encoding itself, which doesn't really fit the definition. I know these things are kind of sticky and we are really in the edge case territory right now, but defining terms well is a very difficult task. I hope you can see why I believe these answers are different. – Wheat Wizard – 2017-12-06T07:11:03.540

Or actually +:0#5g:!_#@,1# + \n which is 15? The newline is calculated manually, rather than fetched. Try it online

– Jo King – 2017-12-06T07:50:01.073

It took me a while to respond because I've been thinking about this. I feel like that is ok, but I think this might be a good place to ask about it on the meta. It certainly seems like a strange edge case. – Wheat Wizard – 2017-12-07T01:32:21.700

1

Funky, 21 bytes

f=@write`f=[f]f()`f()

Try it online!

or, if Functions are allowed...

Funky, 9 bytes

f=@'f='+f

The second of these defines a function f which returns the string f=@'f='+f, the first however is a full program.

Try it online!

ATaco

Posted 2011-01-28T00:34:05.293

Reputation: 6 373

1

Attache, 69 bytes

Save["Save[%c%s%c]Print[Format[_,34,_,34]]"]Print[Format[_,34,_,34]]

Try it online! The trailing newline is significant.

Explanation

Save updates the abstract variable _ with the string

"Save[%c%s%c]Print[Format[_,34,_,34]]"

Then, this string is formatted with the arguments _, 34, _, and 34. This prints the string, the character 34 (a quote), and then those two again, which is the program.

Conor O'Brien

Posted 2011-01-28T00:34:05.293

Reputation: 25 859

1

Locksmith, 201 bytes

070405000400080701090704000102010702070000080006030109000107020001020106070707040507040001020107020700000800060301090001070200010201067450408719740121727008063190172012167774574012172700806319017201216

Try it online!

Formatted:

0704050004000807010907040001020107020700000800060301090001070200010
2010607070704050704000102010702070000080006030109000107020001020106
7450408719740121727008063190172012167774574012172700806319017201216

This consists of two parts: the data section and the decoder. The data section is simply each byte of the encoder prefixed with a 0 (which is the command to push that number). The decoder is:

74              // push stack length
5               // that many times:
   0408719      // output a 0
   74012172     // bring bottom of stack to the top
   700806319    // output this without popping
   0172         // swap top two (brings length to top)
   0121         // decrement
6               // close loop    

7774            // pop counter, push length again
5
   74012172     // bring bottom to top
   700806319    // output
   0172         // bring length to top
   0121         // decrement
6               // close loop

Conor O'Brien

Posted 2011-01-28T00:34:05.293

Reputation: 25 859

1

Swift 4, 120 bytes

import Foundation;let q="import Foundation;let q=%c%@%c;print(String(format:q,34,q,34))";print(String(format:q,34,q,34))

Try See it online!

Since this code imports Foundation, and the Swift corelibs can be a little quirky in non-macOS environments, you might not be able to run it (it doesn't work in TIO, or IBM's Swift Sandbox). If, however, you have a macOS environment, then you should be just fine.

osuka_

Posted 2011-01-28T00:34:05.293

Reputation: 346

1

Stax, 8 bytes

"34bL"34bL

Run and debug online!

Added for completeness. I think this is the shortest proper quine in Stax, but the idea is not that exciting and has been extensively used. I tried to come up with a more interesting (but longer) solution but so far to no avail.

I would also be happy to offer a bounty to a proper quine in Stax in the packed form.

Explanation

"34bL"        Push that string
      34      Push the quotation mark
        b     Duplicate both elements on stack
         L    Pack all elements to an array
              Implicit output

Improper quine:

|?            Source of the program

Weijun Zhou

Posted 2011-01-28T00:34:05.293

Reputation: 1 214

1

Pari/GP, 29 bytes

(f=()->print1("(f="f")()"))()

Try it online!

alephalpha

Posted 2011-01-28T00:34:05.293

Reputation: 18 628

1

Go - 583

Just because d;

package main
import "fmt"
func main(){
    a := string(byte(34))
    b := []string{
        "package main",
        "import fmt",
        "func main(){",
        "   a := string(byte(34))",
        "   b := []string{",
        "       ",
        "   }",
        "   for i:=0;i<5;i++{if i != 1{fmt.Println(b[i])}else{fmt.Println(b[i][:7]+a+b[i][7:]+a)}}",
        "   for _,v:=range b{fmt.Println(b[6]+a+v+a+string(','))}",
        "   for i:=7;i<9;i++{fmt.Println(b[i])}",
        "}",
        }
    for i:=0;i<5;i++{if i != 1{fmt.Println(b[i])}else{fmt.Println(b[i][:7]+a+b[i][7:]+a)}}
    for _,v:=range b{fmt.Println(b[5]+a+v+a+string(','))}
    for i:=7;i<11;i++{fmt.Println(b[i])}
}

globby

Posted 2011-01-28T00:34:05.293

Reputation: 726

this is awesome. – cat – 2015-12-07T14:50:35.037

1

Groovy:

`s='s=\\\';s[0..1]+s[3]+s[0..1]+s[2]*6+s[3..-1]*2';s[0..1]+s[3]+s[0..1]+s[2]*6+s[3..-1]*`2

Edit

Works in GroovyConsole

Ant's

Posted 2011-01-28T00:34:05.293

Reputation: 206

1

D, 85 bytes

enum c=q{import std.stdio;void main(){write("enum c=q{"~c~"};mixin(c);");}};mixin(c);

ratchet freak

Posted 2011-01-28T00:34:05.293

Reputation: 1 286

1

C, 125 84 chars

main(){char*p="main(){char*p=%c%s%c,c='%c',s[256];sprintf(s,p,c,p,c,c);puts(s);}",c='"',s[256];sprintf(s,p,c,p,c,c);puts(s);}

It turns out that my idea was implemented much better:

main(){char*p="main(){char*p=%c%s%c;printf(p,34,p,34,10);}%c";printf(p,34,p,34,10);}

Alexander Bakulin

Posted 2011-01-28T00:34:05.293

Reputation: 369

1You could shave 9 chars off the shorter version by leaving out the trailing newline. – Ilmari Karonen – 2012-02-03T18:55:46.777

1

Ada, 274 258 257 Characters

with Text_IO;use Text_IO;procedure Q is M:Character:='"';T:String:="with Text_IO;use Text_IO;procedure Q is M:Character:=';T:String:=;begin Put_Line(T(1..54)&M&T(54..65)&M&T&M&T(66..126));end Q;";begin Put_Line(T(1..54)&M&T(54..65)&M&T&M&T(66..126));end Q;

pretty printed:

with Text_IO;
use Text_IO;
procedure Quine is
   M : Character := '"';
   T : String := "with Text_IO;use Text_IO;" &
     "procedure Q is M:Character:=';T:String:=;" &
     "begin Put_Line(T(1..54)&M&T(54..65)&M&T&M&T(66..126));end Q;";
begin
   Put_Line(T(1..54)&M&T(54..65)&M&T&M&T(66..126));
end Quine;

this program actually produces the short version (output can be redirected to q.adb).

oenone

Posted 2011-01-28T00:34:05.293

Reputation: 161

1

Cobra - 143

class P
    def main
        s='class P{2}   def main{2}     s={1}{0}{1}{2}      Console.write(s,s,39to char,10to char)'
        Console.write(s,s,39to char,10to char)

Οurous

Posted 2011-01-28T00:34:05.293

Reputation: 4 083

1

Julia, 101 characters

s="s=%c%s%c;@printf %c%s%c 34 s 34 34 s 34";@printf "s=%c%s%c;@printf %c%s%c 34 s 34" 34 s 34 34 s 34

It's the usual format string technique, but unfortunately you can't get the format specification string from a variable in Julia, so I have to include it twice in the code, which blows everything up.

Martin Ender

Posted 2011-01-28T00:34:05.293

Reputation: 162 549

1

Lua, 76 characters

s="s=%c%s%c;print(string.format(s,34,s,34))";print(string.format(s,34,s,34))

Another one with the usual format string technique.

Martin Ender

Posted 2011-01-28T00:34:05.293

Reputation: 162 549

1

Common Lisp - 73 35

Thanks to reader variables written #n= and #n#, with n an integer, Lisp code can be self-referential. Also, the printing functions can emit such reader variables when told to handle circular structures. The WRITE function accepts a :circle parameter for that purpose. It also returns the value being printed, which means that we have to globally set *PRINT-CIRCLE* to T (the initial, standard value is NIL), otherwise the REPL would report a stack-overflow exception when printing that value. Initializing the variable takes a lot of bytes and so the shorter solution is to return another value:

#1=(PROGN (WRITE '#1# :CIRCLE T) T)

coredump

Posted 2011-01-28T00:34:05.293

Reputation: 5 522

1

Python 2, 31 bytes

s="print's=%r;exec s'%s";exec s

It's 2 bytes longer than the shortest Python quine on this question, but it's much more useful, since you don't need to write everything twice.

For example, to print a program's own source code in sorted order, we can just do:

s="print''.join(sorted('s=%r;exec s'%s))";exec s

Another example by @feersum can be found here.

Notes

The reason the quine works is because of %r's behaviour. With normal strings, %r puts single quotes around the string, e.g.

>>> print "%r"%"abc"
'abc'

But if you have a single quotes inside the string, it uses double quotes instead:

>>> print "%r"%"'abc'"
"'abc'"

This does, however, mean that the quine has a bit of a problem if you want to use both types of quotes in the string.

Sp3000

Posted 2011-01-28T00:34:05.293

Reputation: 54 224

1

F♯# - 349 Characters

let s="\\\"\nnlet s=let z a b=s.Substring(a,b)System.Console.WriteLine()z 4 6+z 1 1+z 0 1+z 0 1+z 0 1+z 1 1+z 0 1+z 3 1+z 3 1+z 4 169+z 1 1+z 2 1+z 10 26+z 2 1+z 36 25+z 62 111+z 61 1" 
let z a b=s.Substring(a,b)
System.Console.WriteLine(z 4 6+z 1 1+z 0 1+z 0 1+z 0 1+z 1 1+z 0 1+z 3 1+z 3 1+z 4 169+z 1 1+z 2 1+z 10 26+z 2 1+z 36 25+z 62 111+z 61 1)

My first attempt at a quine - probably an easier (or shorter) way to do it, but not a bad first attempt I don't think

lochok

Posted 2011-01-28T00:34:05.293

Reputation: 1 999

1

Burlesque - 1 byte

Technically, this is a quine:

1

Technically, this is also a quine:

{1 2 3}

Pretty much any literal is a quine.

This is also a quine which doesn't use a simple literal:

,#Q2 SH ~- ",#Q" \/ .+ sh

The comma is not necessary if you launch burlesque in no-stdin mode.

mroman

Posted 2011-01-28T00:34:05.293

Reputation: 866

1

Minkolang 0.9, 10 bytes

This language was made after this challenge, but was not made for it.

"66*2-(O).

Like other 2D languages, the " makes everything between it and the next " a string. 66*2- adds the not-included " and (O). prints everything out and stops.

El'endia Starman

Posted 2011-01-28T00:34:05.293

Reputation: 10 944

1

AppleScript, 2 Bytes

1

It's a little cheaty, but it is following the restrictions of a quine. If we don't count the trailing newline, then this solution becomes 1 byte - 1.

Whenever AppleScript has a final executed line of code, it prints the result of the last operation (whatever it is) to the command line.

text

Any class name has the same effect.

Addison Crump

Posted 2011-01-28T00:34:05.293

Reputation: 8 084

1

Scala, 84 bytes

val d="""
print("val d=\"\"\""+d+"\"\"\""+d)
"""
print("val d=\"\"\""+d+"\"\"\""+d)

Kinda straightforward, but putting it out there for completion.

triggerNZ

Posted 2011-01-28T00:34:05.293

Reputation: 241

1

Seriously, 2 bytes

1

Pushes the number 1, implicit print with trailing newline. Since this is fairly trivial, here is the smallest non-trivial quine which can contain arbitrary characters (12 bytes):

`è";ƒ"@+`;ƒ

quintopia

Posted 2011-01-28T00:34:05.293

Reputation: 3 159

1

Python 3 - 58 Characters

Since there is a Python 2 version, I suppose this is acceptable:

x='x={};print(x.format(repr(x)))';print(x.format(repr(x)))

padawan

Posted 2011-01-28T00:34:05.293

Reputation: 186

1

Java, 190 Characters

class I{public static void main(String[]a){String s="class I{public static void main(String[]a){String s=%c%s%1$c;System.out.print(s.format(s,34,s));}}";System.out.print(s.format(s,34,s));}}

Minimal

Posted 2011-01-28T00:34:05.293

Reputation: 131

1

Reng v.1.3, 7 bytes

Try it out here!

"rYao;~

" begins a quote string, and reads all of those characters. r reverses the stack, and Y pushes the char code of ". a begins a one-way mirror loop, o outputs the character, and ; mirrors while the stack is truthy. After the zero is met, we advance to ~ and the program ends.

Reng v.2, 8 bytes

{n6G*o}`

This one is a little more interesting. {...} is a code block, and ` executes a code block. n outputs the codeblock already on the stack, 6G* makes a ` character (6*16 = 96), and o output's that.

Conor O'Brien

Posted 2011-01-28T00:34:05.293

Reputation: 25 859

1

Java 2146 2118 bytes

A legitimate attempt at a quine. This was automagically generated. I could have robbed someone elses quining technique but decided against it.

interface q{static void main(String[] args){char[] s={32,83,121,115,116,101,109,46,111,117,116,46,112,114,105,110,116,40,34,112,117,98,108,105,99,32,99,108,97,115,115,32,81,117,105,110,101,123,112,117,98,108,105,99,32,115,116,97,116,105,99,32,118,111,105,100,32,109,97,105,110,40,83,116,114,105,110,103,91,93,32,97,114,103,115,41,123,34,41,59,83,121,115,116,101,109,46,111,117,116,46,112,114,105,110,116,40,34,99,104,97,114,91,93,32,115,61,123,34,41,59,102,111,114,40,105,110,116,32,105,61,48,59,105,60,115,46,108,101,110,103,116,104,45,49,59,105,43,43,41,123,83,121,115,116,101,109,46,111,117,116,46,112,114,105,110,116,40,40,105,110,116,41,115,91,105,93,43,34,44,34,41,59,125,83,121,115,116,101,109,46,111,117,116,46,112,114,105,110,116,40,40,105,110,116,41,115,91,115,46,108,101,110,103,116,104,45,49,93,43,34,125,59,34,41,59,102,111,114,40,99,104,97,114,32,99,58,32,115,41,123,83,121,115,116,101,109,46,111,117,116,46,112,114,105,110,116,40,99,41,59,125,125,125,32,83,121,115,116,101,109,46,111,117,116,46,112,114,105,110,116,40,34,112,117,98,108,105,99,32,99,108,97,115,115,32,81,117,105,110,101,123,112,117,98,108,105,99,32,115,116,97,116,105,99,32,118,111,105,100,32,109,97,105,110,40,83,116,114,105,110,103,91,93,32,97,114,103,115,41,123,34,41,59,83,121,115,116,101,109,46,111,117,116,46,112,114,105,110,116,40,34,99,104,97,114,91,93,32,115,61,123,34,41,59,102,111,114,40,105,110,116,32,105,61,48,59,105,60,115,46,108,101,110,103,116,104,45,49,59,105,43,43,41,123,83,121,115,116,101,109,46,111,117,116,46,112,114,105,110,116,40,40,105,110,116,41,115,91,105,93,43,34,44,34,41,59,125,83,121,115,116,101,109,46,111,117,116,46,112,114,105,110,116,40,40,105,110,116,41,115,91,115,46,108,101,110,103,116,104,45,49,93,43,34,125,59,34,41,59,102,111,114,40,99,104,97,114,32,99,58,32,115,41,123,83,121,115,116,101,109,46,111,117,116,46,112,114,105,110,116,40,99,41,59,125,125,125};System.out.print("interface q{static void main(String[] args){");System.out.print("char[] s={");for(int i=0;i<s.length-1;i++){System.out.print((int)s[i]+",");}System.out.print((int)s[s.length-1]+"};");for(char c: s){System.out.print(c);}}}

Rohan Jhunjhunwala

Posted 2011-01-28T00:34:05.293

Reputation: 1 878

1

R, 73 bytes (incl. tabs and newlines)

(f=function()
{
    cat("(f=function()\n")
    print(body(f))
    cat(")()")
}
)()

Shorter, less interesting quines are possible: function()1 is 11 bytes. + (1 byte) is an arguable quine, since the command prompt for an unfinished line is a plus sign by default, and + on its own counts as an unfinished line.

JDL

Posted 2011-01-28T00:34:05.293

Reputation: 1 075

It is necessary to format exactly this way (can't remove tabs or replace newline with ";"), otherwise the output will not exactly match the input. – JDL – 2016-08-25T14:17:25.820

A more trivial example is function()1 (11 bytes) but that's kinda boring... – JDL – 2016-08-26T14:06:21.160

1

Perl 6, 36

printf |(q<printf |(q<%s>xx 2)>xx 2)

Based on the Perl 5 quine.

bb94

Posted 2011-01-28T00:34:05.293

Reputation: 935

1

Julia, 36 bytes

(~=:@printf "(~=:%s)|>eval" ~)|>eval

Try it online!

Background

Unlike many other languages, Julia's eval doesn't work as expected with a string; for example, eval("print(42)") just returns the string print(42).

To actually executed print(42) with eval;, we have to pass an Expr to eval. This can be done by invoking parse on a string (e.g., eval(parse("print(42)"))) or by passing an Expr literal to eval (e.g., eval(:(print(42))).

Now, while : is a unary operator and :print works fine on its own, :print(42) does not, as it is parsed as (:print)(42), making all parentheses in :(print(42)) mandatory.

However, if we use the macro @printf instead, the parsing rules change, and :@printf(42) works as intended. Also, macro calls also do not require parentheses, and :@printf 42 saves one byte over :(print(42)).

How it works

:@printf "(~=:%s)|>eval" ~ constructs the Expr that calls @printf with the specified format string and additional argument ~. Here, ~ is simply a variable reference; the name is arbitrary.

~=<Expr> saves the generated Expr in the variable ~, which will be accessible when the Expr is evaluated.

Finally, (<assigment>)|>eval calls eval with the return value of the assignment, i.e., the Expr that was assigned to ~.

Dennis

Posted 2011-01-28T00:34:05.293

Reputation: 171 923

1

Y, 2 bytes

Try it here!

Up

This is two commands. U is a capture link, and begins quoting the code, and has a U at the beginning of the result. It wraps around, since there is no matching U, and captures the string Up. Then, p prints it, and we are done.

Conor O'Brien

Posted 2011-01-28T00:34:05.293

Reputation: 25 859

1

Aubergine, 21 bytes

-a1+a1=oA=Bi-BA:bB=ia   

This program ends with a trailing tab character.

Oliver Ni

Posted 2011-01-28T00:34:05.293

Reputation: 6 425

Tab character?. – CalculatorFeline – 2017-01-26T21:47:34.140

1I wrote this program in November 2015. I could have sworn I'd posted it here already. Anyway thanks for posting it and no thanks for not giving me credit. – quintopia – 2017-12-15T06:37:11.020

That doesn't make sense, you didn't post it on here, so how would I know you already wrote it lmao – Oliver Ni – 2017-12-16T07:02:03.747

1

Dart, 185 bytes

main(){var c=new String.fromCharCode(34);var l=["main(){var c=new String.fromCharCode(34);var l=[","];print(l[0]+c+l[0]+c+','+c+l[1]+c+l[1]);}"];print(l[0]+c+l[0]+c+','+c+l[1]+c+l[1]);}

Jasper Catthoor

Posted 2011-01-28T00:34:05.293

Reputation: 41

1

Dip, 10 bytes

"N+|+"N+|+

Explanation:

"N+|+"      Push string
      N+    Add " on the left side of the string
        |+  Duplicate and concatenate

acrolith

Posted 2011-01-28T00:34:05.293

Reputation: 3 040

0

Forth (gforth), 21 bytes

: x
latest name-see ;

This prints the decompiled source of the latest word, thus only works if x is the latest defined word.

Test:

x 
: x  
latest name-see ; ok

This one works without that condition, but replaces the constant definition with it's value (since that's the only thing that actually gets saved to memory)

: x
[ latest ] literal name-see ;

Test:

x 
: x  
  140121195205104 name-see ; ok

therealfarfetchd

Posted 2011-01-28T00:34:05.293

Reputation: 569

1If it prints with a newline in the middle, but the original doesn't have it, it's not a quine. – Pavel – 2016-12-29T05:07:04.513

Fixed. It's because there's no way to tell where spaces/newlines are as it's only compiled code – therealfarfetchd – 2016-12-29T13:39:54.790

It's not a proper quine anyway, because it reads its own source. – mbomb007 – 2017-05-10T14:02:43.973

0

Pyke, 14 bytes

"34.Cp\D\Es"DE

Try it here!

"34.Cp\D\Es"   - "34.Cp\D\Es"
            DE - eval(^, stack=^)

 34.C          -   '"'
     p         -  print(^)
      \D\Es    - sum("34.Cp\D\Es", ^, "D", "E")

Blue

Posted 2011-01-28T00:34:05.293

Reputation: 22 461

0

SimpleTemplate, 56 bytes

This is a template engine language I've made for fun.

It was written in PHP and run by compiling the weird syntax to PHP.

This answer is a translation of Aurel Bílý's amazing PHP answer!

{@setF"{@setF%c%s%c}{@printF,34,F,34}"}{@printF,34,F,34}

Weird, right?

This works with the commit d1d3e2c43bd98da2bd38f884ee5ac7b39cb8c579 on my Github and you can try it on http://sandbox.onlinephpfunctions.com/code/cca9ed3b9c87abad61159725f159285e5daf9bb9.

In there, you will have the existing code on that commit, plus showing the result and the generated PHP.

Ismael Miguel

Posted 2011-01-28T00:34:05.293

Reputation: 5 787

0

J, 1 or 2 bytes

6

Will output 6, but it also adds a trailing newline, if the newline is counted then adding a newline to your own program makes them the same.

algorithmshark kinda mentioned this in passing, but I wanted to draw more attention to this solution

Bijan

Posted 2011-01-28T00:34:05.293

Reputation: 516

If a newline is part of the output it should also be part of the program. – Laikoni – 2017-03-14T14:06:18.973

Is that so? I don't think this would be the only program that ignores it. – Bijan – 2017-03-14T14:08:27.627

0

dc, 16 bytes

[91Pn6120568P]dx

Try it online!

Nothing fancy, posting for completeness.

Explanation

[91Pn6120568P]dx
 91P              # Print "["
    n             # Print the macro
     6120568P     # Print "]dx" encoded as a number
[            ]dx  # Run macro on its own code

eush77

Posted 2011-01-28T00:34:05.293

Reputation: 1 170

0

GNU Make, 52 51 11 bytes

$(value $0)

When called as a function, returns its source code.

And here's a complete makefile that doesn't return its code, but rather prints it:

Q=$(info Q=$(value Q))$(info $$(call Q))
$(call Q)

Explanation

The second line just instantiates the variable, the first one defines it:

$(info Q=$(value Q))$(info $$(call Q))
         $(value Q)                     # Get unexpanded value
                           $$           # "$" escaped
$(info Q=          )$(info   (call Q))  # Print the remaining parts

eush77

Posted 2011-01-28T00:34:05.293

Reputation: 1 170

0

Babel, 161 bytes

{ "{ '{ ' << dup [val 0x22 0xffffff00 ] dup <- << << -> << ' ' << << ' }' << } !" { '{ ' << dup [val 0x22 0xffffff00 ] dup <- << << -> << ' ' << << '}' << } ! }%

MD XF

Posted 2011-01-28T00:34:05.293

Reputation: 8 337

0

Ceylon, 173 154 bytes

Saved those bytes thanks to Challenger5

shared void run(){print(let(x="""shared void run(){print(let(x=$)x.replaceFirst("$","\"\"\""+x+"\"\"\""));}""")x.replaceFirst("$","\"\"\""+x+"\"\"\""));}

source

MD XF

Posted 2011-01-28T00:34:05.293

Reputation: 8 337

You can golf off some whitespace. Try it online!

– Esolanging Fruit – 2017-05-25T01:07:44.647

@Challenger5 Cheers :D – MD XF – 2017-05-25T01:10:38.890

0

Perl 5, 37 bytes

$_=q{$_=q{0};s/0/$_/;say};s/0/$_/;say

Try it online!

mik

Posted 2011-01-28T00:34:05.293

Reputation: 155

0

Pretty certain you can't get shorter than this with Common Lisp. The first one I managed to figure out myself; all credit to http://rosettacode.org/wiki/Quine#Common_Lisp for the second one.

Common Lisp - 9 (With REPL)

(write -)

In Common Lisp, - is a special variable that holds the expression currently being evaluated but only during a read-eval-print loop. If you're running from a script or you've disabled the REPL though...

Common Lisp - 25 (No REPL)

#1=(write '#1# :circle t)

This references itself and then prints itself out. :circle t makes it detect the infinite recursion cycle and exit early.

Candles

Posted 2011-01-28T00:34:05.293

Reputation: 673

0

CJam, 1 byte

Note: CJam was made after this challenge was posted, I am posting this answer as documentation as opposed to a serious entry.

0

Pushes a 0 to the stack, and CJam automatically outputs the stack after program execution.

GamrCorps

Posted 2011-01-28T00:34:05.293

Reputation: 5 255

Don't forget newlines. – CalculatorFeline – 2017-05-28T01:39:09.793

0

ForceLang with this module, 87 bytes

Noncompeting, language postdates the challenge

set j require njs
j var f=function(){print("set j require njs\nj var f="+f+";f()")};f()

SuperJedi224

Posted 2011-01-28T00:34:05.293

Reputation: 9 433

0

Idris, 88 bytes

q:String;main:IO();main=putStr$q++show q;q="q:String;main:IO();main=putStr$q++show q;q="

It’s like Haskell with more enforced top-level type signatures. I had to put q’s type first, because Idris’s type checker is a little weird? I dunno.

Lynn

Posted 2011-01-28T00:34:05.293

Reputation: 41 980

0

Clean, 123 bytes

module q;import StdEnv,GenPrint;Start=s+++printToString s;s="module q;import StdEnv,GenPrint;Start=s+++printToString s;s="

Save as q.icl and compile with -b -nt.

Keelan

Posted 2011-01-28T00:34:05.293

Reputation: 435

0

Scala, 56 bytes

val s="val s=%c%s%c;printf(s,34,s,34)";printf(s,34,s,34)

First defines s as val s=%c%s%c;printf(s,34,s,34), then prints it formatted with double quotes (ascii 34) and itself.

corvus_192

Posted 2011-01-28T00:34:05.293

Reputation: 1 714