206
\$\begingroup\$

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 bytes)
  • Most obfuscated/obscure solution
  • Using esoteric/obscure languages
  • Successfully using languages that are difficult to golf in

The following Stack Snippet 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 OVERRIDE_USER=98;

var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";var COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk";var answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,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:!0,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=!1;comment_page=1;getComments()}})}
function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(data){data.items.forEach(function(c){if(c.owner.user_id===OVERRIDE_USER)
answers_hash[c.post_id].comments.push(c)});if(data.has_more)getComments();else if(more_answers)getAnswers();else process()}})}
getAnswers();var SCORE_REG=(function(){var headerTag=String.raw `h\d`
var score=String.raw `\-?\d+\.?\d*`
var normalText=String.raw `[^\n<>]*`
var strikethrough=String.raw `<s>${normalText}</s>|<strike>${normalText}</strike>|<del>${normalText}</del>`
var noDigitText=String.raw `[^\n\d<>]*`
var htmlTag=String.raw `<[^\n<>]+>`
return new RegExp(String.raw `<${headerTag}>`+String.raw `\s*([^\n,]*[^\s,]),.*?`+String.raw `(${score})`+String.raw `(?=`+String.raw `${noDigitText}`+String.raw `(?:(?:${strikethrough}|${htmlTag})${noDigitText})*`+String.raw `</${headerTag}>`+String.raw `)`)})();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,})});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('<i>'+a.language+'</i>').text().toLowerCase();languages[lang]=languages[lang]||{lang:a.language,user:a.user,size:a.size,link:a.link,uniq:lang}});var langs=[];for(var lang in languages)
if(languages.hasOwnProperty(lang))
langs.push(languages[lang]);langs.sort(function(a,b){if(a.uniq>b.uniq)return 1;if(a.uniq<b.uniq)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)}}
body{text-align:left!important}#answer-list{padding:10px;float:left}#language-list{padding:10px;float:left}table thead{font-weight:700}table td{padding:5px}
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/Sites/codegolf/primary.css?v=f52df912b654"> <div id="language-list"> <h2>Winners 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><a href="{{LINK}}">{{SIZE}}</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td><a href="{{LINK}}">{{SIZE}}</a></td></tr></tbody> </table> 

\$\endgroup\$
  • 4
    \$\begingroup\$ Do you not mean, "Golf you a quine for greater good!"? \$\endgroup\$ – Mateen Ulhaq May 3 '11 at 2:49
  • 54
    \$\begingroup\$ @muntoo it's a play on "Learn you a Haskell for Great Good". \$\endgroup\$ – Rafe Kettler May 3 '11 at 2:52

350 Answers 350

1
8 9 10
11
12
1
\$\begingroup\$

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!

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Aubergine, 21 bytes

-a1+a1=oA=Bi-BA:bB=ia   

This program ends with a trailing tab character.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Tab character?. \$\endgroup\$ – CalculatorFeline Jan 26 '17 at 21:47
  • 1
    \$\begingroup\$ I 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. \$\endgroup\$ – quintopia Dec 15 '17 at 6:37
  • 1
    \$\begingroup\$ That doesn't make sense, you didn't post it on here, so how would I know you already wrote it lmao \$\endgroup\$ – Oliver Ni Dec 16 '17 at 7:02
1
\$\begingroup\$

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
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

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.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Perl 5, 37 bytes

$_=q{$_=q{0};s/0/$_/;say};s/0/$_/;say

Try it online!

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Javascript REPL, 21 bytes

(_=$=>`(_=${_})()`)()
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Foo, 136 111 96 bytes

I'm surprised to see that there's no Foo quine here yet!

>&41>&60>&99>&36>&40>&60>&41>&62>&105>&36>&34>&38>&62>&34>&40>&62>&41>&60>&40(<)>(">&"$i>)<($c<)

Try it online!

Explanation

This is pretty simple as far as quines go. There are two sections: the data and the decoder. The data is encoded on the array, and is decoded as such:

(<)>(">&"$i>)<($c<)

Which basically iterates once over the tape, outputting >& and the integer value of the cell, then iterating once again over the tape, outputting each character. The tape, then, is just the character codes of this decoder.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Yabasic, 103 bytes

An anonymous Yabasic quine

c$=Chr$(34):q$="c$=Chr$(34):q$=:?Left$(q$,15)+c$+q$+c$+Mid$(q$,16)":?Left$(q$,15)+c$+q$+c$+Mid$(q$,16)

Includes a trailing newline

Try it online!

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Pascal (FPC), 103 bytes

const s=#39'const s=#39;begin write(s[2..12],s,s[10..50])end.'#39;begin write(s[2..12],s,s[10..50])end.

Try it online!

s is the string that the output is generated from. In Pascal, subtrings can be easily extracted with [from..to] syntax. #39 is replacement for ' using its ASCII codepoint. As seen in this program, sequences of character codepoints can be glued together with the rest of the string delimited with 's at any time. s consists of characters before and after 's concatenated together. #39 occurs immediately before first ' and after second ' so it can be put in s only once and used in both substrings in the output.

 
The version that may be more suitable in modified, quine-like programs is at 106 bytes:

const s='const s=;begin write(s[1..8],#39,s,#39,s[9..52])end.';begin write(s[1..8],#39,s,#39,s[9..52])end.

Try it online!

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

!@#$%^&*()_+, 76 bytes

40Kjiiiiiiiiiiij,306j,6641,iK31,i,6j,,!!_+!^!&(@^!&)++!_+%(!_^^^^^^^^^^^_@%)

Try it online!

The code can be decomposed into two sections: the data and the decoder. The data is this:

40Kjiiiiiiiiiiij,306j,6641,iK31,i,6j,,

Each character pushes itself, and corresponds to a command (shifted up by 11).

The decoder is this:

!!_+!^!&(@^!&)++!_+%(!_^^^^^^^^^^^_@%)

This can also be divided into two parts, one which prints the data raw, and one which decodes the data. This part prints the initial data segment:

!!_+!^!&(@^!&)++!_+%
!!_+                     push 0 (duplicate twice then subtract)
                         this is our delineator
    !^                   push 1 (duplicate and increment)
                         this is our pointer
      !&                 push the entry at that index in the stack
        (    )           until the dilineator is found:
         @               output the stack entry
          ^              increment pointer
           !&            refresh entry at index
              ++!_+      pop top two (add twice, duplicate, subtract)
                   %     push 0 underneath stack

Then the decoder:

(!_^^^^^^^^^^^_@%)
(               %)    For each character:
 !_           _           subtract
   ^^^^^^^^^^^            11
               @          and output it
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Muriel, 36 bytes

A:"\";.\"A:\\\"\"+|A+A";."A:\""+|A+A

Try it online!

Since Muriel isn't on TIO (yet!), I've included the interpreter in the link. Thanks Dennis!

Quines are the base component of any complex Muriel program, since they're a requirement for any sort of loop.

Explanation:

A:        Assign to A
  "       ...         "; An escaped version of ";."A:\""+|A+A
                        .          Print
                         "A:\""          A:"
                               +|A       Escaped version of A
                                  +A     Then A itself
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Aubergine, 16 bytes

-a1+a1=oA:bA=iB

Try it online!

The program has a trailing null byte. Works similarly to my hello world.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Perl 6, 36

printf |(q<printf |(q<%s>xx 2)>xx 2)

Based on the Perl 5 quine.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Brachylog v2, 12 bytes

"~k;?w₁";?w₁

Try it online!

Full program. Essentially a translation of Fatalize's (non-builtin) Brachylog v1 answer, although it also uses different SWI-Prolog formatting sequences, or rather, a single different one, which saves about 20 bytes (both [34:s, both :34]s, and both ~cs). It seems to have existed back in 2016, but it was probably bugged or something. The last two bytes saved come from using the implicit input, which Brachylog being Brachylog is useful even when the program receives no input, because it's a variable (so instead of explicitly unifying the string with S, we just let it be implicitly unified with ?).

          w     Print
"~k;?w₁"        "~k;?w₁"
                which is the input
           ₁    formatted with
        ;?      the input.
 ~k             (so that the ~k is replaced with the input's canonical representation, i.e. in quotes)

We don't actually need to use implicit input--"~kgjw₁"gjw₁ works just as well (and might even translate back to v1)--but doing so regardless manages to both more closely mirror the structure of the original and feel cleverer.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Pip, 26 23 bytes

Y\"O"Y"ORPyy\"O"Y"ORPyy

Try it online!

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

C (gcc), 85 bytes

#define q(k)main(){puts(#k"\nq("#k")");}
q(#define q(k)main(){puts(#k"\nq("#k")");})

Try it online!

The q() macro expands into a program that prints out its argument on the first line, and prints out the argument called by q() itself in the second line. So:

#define q(k)main(){puts(#k"\nq("#k")");}
q(foo)

would expand into:

main(){puts("foo""\nq(""foo"")");}

and after string literal concatenation, becomes:

main(){puts("foo\nq(foo)");}

And executing and running the program would produce:

foo
q(foo)

Replacing foo with the macro definition itself results in the quine.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

C, 353 bytes

char q[]={125,59,109,97,105,110,40,41,123,112,114,105,110,116,102,40,34,99,104,97,114,32,113,91,93,61,123,34,41,59,99,104,97,114,42,112,61,113,59,119,104,105,108,101,40,42,112,41,112,114,105,110,116,102,40,34,37,100,44,34,44,42,112,43,43,41,59,112,117,116,115,40,113,41,59,125,};main(){printf("char q[]={");char*p=q;while(*p)printf("%d,",*p++);puts(q);}
| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ With some golfing, including changing it from hexadecimal to decimal, this can be 354 bytes \$\endgroup\$ – Jo King Aug 2 '19 at 2:04
  • 1
    \$\begingroup\$ The link itself is a gcc compiler and it works fine. Are you sure they aren't just warnings? \$\endgroup\$ – Jo King Aug 2 '19 at 2:51
  • 1
    \$\begingroup\$ If only the output is erroring, then what is the difference between the two programs? What version of gcc are you using? \$\endgroup\$ – Jo King Aug 2 '19 at 3:15
  • 1
    \$\begingroup\$ ... What is the difference between the code of the two programs, not their behaviour. I already know that the second one fails. The version TIO uses is 8.3, and that works fine. \$\endgroup\$ – Jo King Aug 2 '19 at 3:32
  • 1
    \$\begingroup\$ I don't care about the output of the second generation quine. I would like to know the output of the first program, the one that didn't fail and produced something that did. I don't want to know about the errors that you have commented about several times already. I would like to know the difference between the program I have given you and its output. You can put the program in an online compiler like I have and link it in a comment below. \$\endgroup\$ – Jo King Aug 2 '19 at 3:49
1
\$\begingroup\$

Javascript (REPL), 23 22 21 bytes

someone else posted this first

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

paste into chrome console or equivalent to test

JavaScript (V8), 49 48 47 bytes

@NieDzejkob saved 1 byte on both versions

console.log((_=x=>`console.log((_=${_})())`)())

Try it online!

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Wren, 287 bytes

var a="[118,97,114,32,97,61,34].each{|m|System.write(String.fromCodePoint(m))}
System.write(a+String.fromCodePoint(34)+String.fromCodePoint(10)+a)"
[118,97,114,32,97,61,34].each{|m|System.write(String.fromCodePoint(m))}
System.write(a+String.fromCodePoint(34)+String.fromCodePoint(10)+a)

Try it online!

Explanation

var a=                                                                         // Define the variable a
      "[118,97,114,32,97,61,34].each{|m|System.write(String.fromCodePoint(m))}
System.write(a+String.fromCodePoint(34)+String.fromCodePoint(10)+a)"           // As the string that processes the variable

                                                                               // A literal newline is inserted and can be decoded literally.

[118,97,114,32,97,61,34].each{|m|System.write(String.fromCodePoint(m))}        // Output the string "var a=" to the console
System.write(                                                                  // Output without a newline:
             a                                                                 // The string a
              +String.fromCodePoint(34)                                        // Plus a quote
                                       +String.fromCodePoint(10)               // Plus a newline
                                                                +a)            // Plus the string again
```
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Why doesn't fromByte work in place of fromCodePoint? \$\endgroup\$ – Jo King Oct 29 '19 at 23:28
  • \$\begingroup\$ I have absolutely no idea. \$\endgroup\$ – user85052 Oct 30 '19 at 3:57
1
\$\begingroup\$

Symbolic Raku, 36 bytes

$_={$_~"<$_>)"}(<$_={$_~"<$_>)"}(>)

Try it online!

Explanation:

$_=                                   # Set the output to
   {          }(                  )   # The result of the code block
                <                >    # With this string:
                 $_={$_~"<$_>)"}(        # The first half of the program
    $_~                               # Concatenate this string with
       "<$_>)"                        # The quoted string, and the extra bracket
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Keg, 8 6 4 bytes

`④`④

Try it online!

Answer History

8 bytes

`:.,`:.,

Try it online!

Why did it take me so long to figure out how to write a quine in Keg? I really should have picked up on this sooner.

Basically, it pushes the string :.,, duplicates it, prints the string repr'd and then prints it nicely.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

W, 13 bytes

Print the data string & prepend quote.

p34CS+"p34CS+
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

tq, 8 bytes

New high-level language! (Technically inspired by Jo King's Symbolic Raku quine.)

etq'etq'

Explanation

   'etq' # Define the second item of the list
         # As a string
  q      # Surround the string with quotes
 t       # For the first item of the list,
         # Access the last (tail) item in the list,
e        # and un-quote the accessed value.

# The list becomes etq, 'etq' (comma is for readability)
# , which then becomes foreach-printed without any separator.
```
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Common Lisp, 58 bytes

Lisp is perfect for quines because of using code as data, but terseness is not its strong suit.

(FORMAT T "(~{~S ~}~:*'~S)" '(FORMAT T "(~{~S ~}~:*'~S)"))

Excellent expert explanation.

(FORMAT T  -- print
"(      )" -- between parentheses
" ~{  }~ " -- looping over the list argument
" ~S_    " -- each item followed by a space
"   ~:*  " -- use the FORMAT sublanguage's *very* fancy
             -- "~*" directive (skip argument) with the ":"
             -- modifier to back up and reuse the argument
"    '~S " -- print the argument again with a quote before it
    '(FO.. -- the argument is the same thing but with a quote
             -- in front to show that it is data

Ideone it!

Alternative 9 bytes, that only works in the REPL

(prin1 -)

(use print for a trailing newline)

This prints the value of '-', which is the current expression being evaluated. You can try it here.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Perl 5 + -p, 35 bytes

A fishy quine!

}{s<><}{s<><@>;s<@><lc>e>;s<@><lc>e

Try it online!

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Aceto, 66 bytes

£"24«cs%55«3+cp24«2+cdpsdpsppn"24«cs%55«3+cp24«2+cdpsdpsppn

Kind of a classic quine, but having to deal with a few quirks of Aceto to make it work. I had attempted this in the past but had failed.

This mostly follows the good old "source code in quotes, followed by printing a quote character and the source code twice" method.

Explanation:

£"24«cs%55«3+cp24«2+cdpsdpsppn"24«cs%55«3+cp24«2+cdpsdpsppn
£                                                            # (1)
 "24«cs%55«3+cp24«2+cdpsdpsppn"                              # (2)
                               24«cs%                        # (3)
                                     55«3+cp24«2+cdpsdpsppn  # (4)

Because of the development process of a quine, I decided to ignore the Hilbert curve in this case, because otherwise I'd need to scramble the source code to match the formatting. Therefore we write everything in a single line, exploiting the fact that it will be well-ordered still (just walk over a bunch of nops (spaces) in-between).

  1. I just realized getting an empty string is not really trivial in Aceto (oops). Character literals (starting with ') are always 1 character long. You could use string literals, but just doing "" will only work sometimes, depending on where on the hilbert curve you are currently. Since we're trying to avoid the curve for this (as described above), this will usually just turn into a string containing a couple of spaces. But when the stack is empty (such as at the beginning of the execution), we can "implode" (£) the stack into a single string, which will then be the empty string.
  2. This is, as usual, just the remaining source code after this, as a string literal.
  3. I will need to remove all spaces from the source code that have agglomerated there due to the Hilbert-curve. I can't use a space literal for several reasons (Hilbert curve, and it should be trimmed later), so I instead construct it (and other characters later) using arithmetical operations. An ASCII space is 2, bit-shifted to the left 4 times (24«c). We then use the regex substitution operator % to remove the spaces.
  4. Now we're ready to print things: We construct the pound symbol (55«3+c) and print it, followed by a double-quote (24«2+c), followed by the space-trimmed source code, a quote, and the source code again. Finally, we print a newline (n).
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Integral, 18 12 Bytes

⌡^♦►◙►⌡^♦►◙►

Try it not on TIO!

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Can you update this? A resolution is in the issues on the GitHub. \$\endgroup\$ – nph Aug 5 at 15:56
  • \$\begingroup\$ ⌡^♦►◙►⌡^♦►◙► (12 bytes). Same length as your previous 12-byter, but with the "bug" fixed. \$\endgroup\$ – petStorm 2 days ago
0
\$\begingroup\$

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

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

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.

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

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.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Don't forget newlines. \$\endgroup\$ – CalculatorFeline May 28 '17 at 1:39
  • 1
    \$\begingroup\$ One part of the program does not encode another, so this program is invalid \$\endgroup\$ – MilkyWay90 Feb 5 '19 at 18:04
1
8 9 10
11
12

Your Answer

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

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