204
\$\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
  • 50
    \$\begingroup\$ @muntoo it's a play on "Learn you a Haskell for Great Good". \$\endgroup\$ – Rafe Kettler May 3 '11 at 2:52

337 Answers 337

1
\$\begingroup\$

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)
\$\endgroup\$
1
\$\begingroup\$

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

\$\endgroup\$
  • \$\begingroup\$ After I posted this I was curious if there was an extant AWK quine example. Apparently so at nyx.net/~gthompso/self_awk.txt. Given that, I believe this might be the shortest possible AWK quine. \$\endgroup\$ – Robert Benson Feb 23 '17 at 21:07
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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})"})`
\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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

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.

\$\endgroup\$
1
\$\begingroup\$

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

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
\$\endgroup\$
  • \$\begingroup\$ @Downvoter I can kind of understand the downvotes on all the quines I posted from RosettaCode, but this one, really? \$\endgroup\$ – MD XF May 25 '17 at 17:23
1
\$\begingroup\$

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.
\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

Bash, 54 52 bytes

-2 thanks to Ørjan Johansen

a=\' b='a=\\$a b=$a$b$a\;eval echo \$b';eval echo $b
\$\endgroup\$
  • \$\begingroup\$ The spaces after the semicolons seem unnecessary. \$\endgroup\$ – Ørjan Johansen May 27 '17 at 2:06
  • \$\begingroup\$ @ØrjanJohansen Oh, I completely forgot to golf that part! Thanks :D \$\endgroup\$ – MD XF May 27 '17 at 2:27
  • \$\begingroup\$ You forgot to include the new length. \$\endgroup\$ – Ørjan Johansen May 27 '17 at 2:39
  • \$\begingroup\$ @ØrjanJohansen Is there any limit to how helpful you can be :P \$\endgroup\$ – MD XF May 27 '17 at 2:40
1
\$\begingroup\$

><>, 42 Bytes

'r3d*>l?\ao"/o \     "ooooooooo;
     \ o/

Try it online

\$\endgroup\$
1
\$\begingroup\$

shortC, 38 28 bytes

AR_="AR_=%c%s%1$c,34,_",34,_

Try it online!

\$\endgroup\$
1
\$\begingroup\$

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

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

Add++, 14 bytes

L,"L,%rd%%"d%

Try it online!

Takes advantage of Python string formatting with the % command.

\$\endgroup\$
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!

\$\endgroup\$
1
\$\begingroup\$

Aubergine, 21 bytes

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

This program ends with a trailing tab character.

\$\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
\$\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.

\$\endgroup\$
1
\$\begingroup\$

Swift 4, 63 bytes

let s=[";print(\"let s=\\(s)\"+s[0])"];print("let s=\(s)"+s[0])

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Javascript REPL, 21 bytes

(_=$=>`(_=${_})()`)()
\$\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.

\$\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!

\$\endgroup\$
1
\$\begingroup\$

Excel, 17 Bytes

In cell A1...

=FunctionText(A1)

I discovered this yesterday by accident. Feels a bit cheaty somehow though. I appreciate this answer much more, but this does seem to be a quine :D

\$\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!

\$\endgroup\$

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.