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

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.

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

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

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

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

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

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.

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

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

Dip, 10 bytes

"N+|+"N+|+

Explanation:

"N+|+"      Push string
      N+    Add " on the left side of the string
        |+  Duplicate and concatenate
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Zetaplex, 13 bytes

"Sr34SZOsDrFe

Zetaplex is a variant of gammaplex. In it, commands are pairs of chars and act on an infinite stack.

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

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 :!.

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

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.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Note simply 3 works too, but that is too much of an obvious reading-from-the-source. \$\endgroup\$ – devRicher Dec 26 '16 at 22:33
1
\$\begingroup\$

D, 85 bytes

enum c=q{import std.stdio;void main(){write("enum c=q{"~c~"};mixin(c);");}};mixin(c);
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Racket, 90 bytes

((lambda (x) (display (list (~a x) (~v x)))) '(lambda (x) (display (list (~a x) (~v x)))))
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – clismique Jan 23 '17 at 9:37
  • \$\begingroup\$ Not in this case, because the input has to match the printed output \$\endgroup\$ – Matthew Butterick Jan 23 '17 at 13:12
  • \$\begingroup\$ Oh... yeah, whoops. I'm just looking at the spaces and thinking that they can be golfed somehow. Well, TIL. \$\endgroup\$ – clismique Jan 23 '17 at 22:00
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)
| improve this answer | |
\$\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 :)

| improve this answer | |
\$\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.

| improve this answer | |
\$\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.

| improve this answer | |
\$\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})"})`
| improve this answer | |
\$\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.

| improve this answer | |
\$\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.

| improve this answer | |
\$\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
| improve this answer | |
\$\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.

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

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

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

shortC, 38 28 bytes

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

Try it online!

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

| improve this answer | |
\$\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.

| improve this answer | |
\$\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.

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