237
\$\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\$
3
  • 6
    \$\begingroup\$ Do you not mean, "Golf you a quine for greater good!"? \$\endgroup\$ May 3, 2011 at 2:49
  • 64
    \$\begingroup\$ @muntoo it's a play on "Learn you a Haskell for Great Good". \$\endgroup\$ May 3, 2011 at 2:52
  • 23
    \$\begingroup\$ Did anybody notice that this is question 69? \$\endgroup\$
    – aidan0626
    Oct 24, 2020 at 22:47

432 Answers 432

1
9 10
11
12 13
15
2
\$\begingroup\$

33, 26 bytes

"34cktptptptp"34cktptptptp

Try it online!

Explanation:

"34cktptptptp"             (The instructions)
              34ck         (Load 34 (") into destination string)
                  tp       (Print it)
                    tp     (Print the instructions)
                      tptp (Repeat)
\$\endgroup\$
2
\$\begingroup\$

Corea, 11 bytes

<0C>;"<0C>;

Try it online!

Alternatively, <0C>>"<0C>>

<0C>;"<0C>;
<0C>;            set the contents to that literal string
     "           start command sequence
      <          push a copy of the contents to the stack
       0C        push a quote "
         >       append that to the contents
          ;      and append the original copy and stop command sequence
\$\endgroup\$
2
\$\begingroup\$

Alchemist, 299 bytes

_->14733272090064622117723033634640281434301133345502153207896692199003336573010981052872005814325038964478266287468505274190371239580629370336756929651609657090021232407437472153714372752689076920028135a+Out_"_->"+Out_a+d
d+0e->118b
a+b->o
118o->c+d
0a+0e+c->Out'o+e
e+b->e+o
e+d+c->e+d+a
0c+e+d->d

Try it online!

I'm posting this as a separate answer to my existing one since it uses newer features (character output). This functions much the same but with less logic regarding the modulo values, countered partially by the number being in base 118 instead of base 9. Here is an encoder that can be used to encode the large number up front.

\$\endgroup\$
2
\$\begingroup\$

Poetic, 2100 1896 bytes

-204 bytes by using ASCII 255 and 1 instead of ASCII 122 and 123.

ÿÿÿ ÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿÿ ÿÿÿÿÿ ÿ ÿÿÿÿÿÿ ÿ ÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿ ÿÿÿÿÿ ÿÿ ÿÿÿ ÿ ÿÿÿÿÿÿ ÿÿÿ ÿ ÿÿÿÿÿÿ ÿ ÿÿ ÿÿÿÿÿÿ ÿÿ ÿÿÿÿ ÿ ÿÿ ÿÿÿÿÿ ÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿ ÿÿÿÿÿÿ ÿ ÿÿÿÿ ÿ ÿÿ ÿÿÿÿÿ ÿ ÿ ÿÿÿÿÿ ÿ ÿÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿÿÿÿ ÿÿÿÿÿ ÿÿ ÿÿÿ ÿÿÿ ÿ ÿÿÿÿÿÿ ÿ ÿÿ ÿÿÿÿÿÿ ÿÿ ÿÿ ÿÿÿÿÿ ÿÿÿ ÿ ÿÿÿÿÿ ÿ ÿÿ ÿÿÿÿÿÿ ÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿÿ ÿ ÿÿÿÿÿÿ ÿ ÿ ÿÿÿÿÿ ÿ ÿÿÿÿÿÿÿ ÿÿÿÿÿÿ ÿ ÿÿÿÿ ÿ ÿÿ ÿÿÿÿÿ ÿ ÿÿÿ ÿÿ ÿÿÿÿÿÿÿ ÿÿÿÿÿÿ ÿÿ ÿÿ 

(All of the space characters are actually ASCII code 1, or SOH. StackExchange doesn't seem to like unprintables all that much.)

Try it online!

Poetic is an esolang I made in 2018 for a class project. It's basically brainfuck with word-lengths instead of symbols.

This isn't a terribly Poetic program (it's only two distinct characters), but it's the most compact solution for writing commands that I was able to come up with.

Basically, the core of the program is code that takes tape values corresponding to Poetic commands in a line, adds values to the beginning that would put these values on the tape when executed, and then outputs the values as Poetic commands. The initial values on the tape are, of course, an encoded version of that code. (Standard stuff, surely, but it took me a while to wrap my head around it.)

\$\endgroup\$
1
  • \$\begingroup\$ Unless Poetic uses a custom code page/encoding, this is actually 3312 bytes as ÿ is 2 bytes in TUF-8 \$\endgroup\$ Aug 9, 2020 at 23:16
2
\$\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
\$\endgroup\$
2
\$\begingroup\$

Javascript, 133 bytes

a="\\";b="\"";d="throw b+'HELP!'+b+'a='+b+a+a+b+';b='+b+a+b+b+';d='+b+d+b+';'+d";throw b+'HELP!'+b+'a='+b+a+a+b+';b='+b+a+b+b+';d='+b+d+b+';'+d
\$\endgroup\$
2
\$\begingroup\$

Ral, 1389 1043 bytes

1111111101011101011101010101111101011101010101111101010101111101011101010101111101010101111101011101010101111000111000111000111000111000110101010000110101110111011101011101010101111101011101010101111101011101010101111101011101010101111101011101010101111101011011010101111111111101011101010101111101011101010101111101010101111101011101010101111101011101010101111000111000111000111000110101010000111011010101010000110101111111010111011101011101010101111101010101111101010101111101010101111101011000111101011000111000110101110101010101111101011000111111111101011101010101111101010101111101011101010101111101011101010101111000111000111000110101010000110101111011010101011011010000111000111000111011111011111011010000111000110101111011110000110101111101010101111011011101010101111101010101111101010101111101010101111101010101111101010101111101011101010101111101011101010101111000111000111000111000111111:++:++:+:+:+:+:+:+-:+:0=:10-==110-*-:0*111:++:++:+:++?1+:*:11+1+:+:+:+:++./:0*-0*1111:++:++:+:++:++?:-+:++:++:++:++:++.:0*11111:++:+:++:+:++:+++?

Try it online!

Explanation

All characters in Ral (except the no-op) are in the range 32-63, which is 001xxxxx in binary. By omitting the leading zeroes, every character in the code can be stored as a group of 6 bits. (A hexad? hextet? Hextet will do.) The one is still included in the payload to make decoding easier.

Here is a short summary of what each part of the code does. I have omitted the value juggling on the stack and inner workins of the loops from the explanation, as they would make the explanation too complicated:

111111...100011                Push the payload data to the stack.

1111:++:++:+:+:+:+:+:+-:+:0=   Load the value 894, which is the length of the payload
                               and is used as a base pointer for the jump destinations.

:10-==110-*-:0*111:++:++:+:++? Move the payload data to memory.

1+:*:11+1+:+:+:+:++.           Loop through the payload, printing 48+n for each value
/:0*-0*1111:++:++:+:++:++?     and push each value to the stack again.

:-+:++:++:++:++:++.            Decode and print each hextet.
:0*11111:++:+:++:+:++:+++?
\$\endgroup\$
2
\$\begingroup\$

Python 3, 190 216 bytes

s='s=\\\'\'+s.replace(\'\\\\\',\'\\\\\\\\\').replace(\'\\\'\',\'\\\\\\\'\')+\'\\\'\\nprint(\\\'\'+s+\'\\\')'
print('s=\''+s.replace('\\','\\\\').replace('\'','\\\'')+'\'\nprint(\''+s+'\')')

Try it online!

An old solution of mine following the standard pattern. It only uses the most common commands though.

\$\endgroup\$
2
  • \$\begingroup\$ Nice answer! I have edited in a link to the online interpreter, in case people want to test out your code. \$\endgroup\$ Jun 1, 2020 at 10:48
  • 1
    \$\begingroup\$ You can save a few bytes by removing the redundant spaces. Try it online! \$\endgroup\$ Jun 1, 2020 at 10:54
2
\$\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).
\$\endgroup\$
2
\$\begingroup\$

Integral, 18 12 Bytes

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

Try it not on TIO!

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

(()), 3560 bytes

Let
(
=()
Let
)
=(())
Let


=(()())
Let
L
=((()))
Let
e
=(()(()))
Let
t
=((())())
Let
=
=(((())))
(((()(()))(()))(()()()(())(())(())()()(())()()(())(())(())()()()(())(())()(())(())()()(())()(())(())()(())()()(())()(())(())()()()()(())(())(())(())()(())()()(())(())()()(())()(())(())()()()(())(())(())()()(())()()(())(())(())()()()(())(())()(())(())()()(())()(())(())()()(())(())()()(())()(())(())()()()()(())(())(())(())()(())()(())()()(())(())()()(())(())()()(())()(())(())()()()(())(())(())()()(())()()(())(())(())()()()(())(())()(())(())()()(())()(())(())()()(())()(())(())()()(())()(())(())()()()()(())(())(())(())()(())()(())()()(())(())()(())()()(())(())()()(())(())()()(())()(())(())()()()(())(())(())()()(())()()(())(())(())()()()(())(())()(())(())()()(())()(())(())()()()(())(())(())()()(())()(())(())()()()()(())(())(())(())()(())()(())()(())()()(())(())()()(())(())()()(())(())()()(())()(())(())()()()(())(())(())()()(())()()(())(())(())()()()(())(())()(())(())()()(())()(())(())()()(())()()(())(())(())()()(())()(())(())()()()()(())(())(())(())()(())()(())()()(())(())()(())()(())()()(())(())()()(())(())()()(())(())()()(())()(())(())()()()(())(())(())()()(())()()(())(())(())()()()(())(())()(())(())()()(())()(())(())()()()(())(())()(())(())()()(())()(())(())()()()()(())(())(())(())()(())()(())()(())()()(())(())()()(())(())()(())()()(())(())()()(())(())()()(())()(())(())()()()(())(())(())()()(())()()(())(())(())()()()(())(())()(())(())()()(())()(())(())()()()()(())(())(())(())()()(())()(())(())()()()()(())(())(())(())()(())()(())()(())()(())()()(())(())()()(())(())()()(())(())()()(())(())()()(())()(())(())()(())()(())()(())()(())()()(())(())()(())()(())()()(())(())()()(())(())()()(())(())()(())()(())()()(())(())()()(())(())()()(())(())()(())()()()(())(())(())()()(())()()(())(())(())()()(())(())()()()(())(())(())()()(())(())()()(())(())()(())()(())()(())()(())()(())()(())()()(())(())()()(())(())()()(())(())()(())()(())()(())()()(())(())()()(())(())()()(())(())()()(())(())()(())()()(())(())()()(())(())()()(())(())()(())()(())()(())()(())()(())()()(())(())()()(())(())()()(())(())()(())()()(())(())()()(())(())()(())()(())()()(())(())()(())()(())()()(())(())()()(())(())()(())()(())()(())()()(())(())()()(())(())()()(())(())()()(())(())()()(())(())()(())()(())()(())()(())()(())()()(())(())()()(())(())()()(())(())()(())()(())()()(())(())()()(())(())()()(())(())()(())()(())()()(())(())()(())()()(())(())()(())()(())()()(())(())()()(())(())()(())()(())()()(())(())()()(())(())()(())()(())()(())()()(())(())()()(())(())()()(())(())()()(())(())()()(())(())()(())()(())()()(())()()(())(())(())()()(())(())(())(())))(((((()))((())))()))((((()))())(()(())((()))))((((()))(()))(()()(())(())((()))))((((()))(()(()))((())())(()())()(()())(((())))()(())(()())((()))(()(()))((())())(()())(())(()())(((())))()()(())(())(()())((()))(()(()))((())())(()())(()())(()())(((())))()()(())()(())(())(()())((()))(()(()))((())())(()())((()))(()())(((())))()()()(())(())(())(()())((()))(()(()))((())())(()())(()(()))(()())(((())))()()(())()()(())(())(())(()())((()))(()(()))((())())(()())((())())(()())(((())))()()()(())(())()(())(())(()())((()))(()(()))((())())(()())(((())))(()())(((())))()()()()(())(())(())(())(()())()()()()(())()()(())(())(())()()(())(())(())()((()))(()(()))(())((()))(())(())()()()()()()(())(())(())()()()(())(())(())(())()(())(())(())()()()()()(())(())(())()(())(())()()(())()()(())(())()()()(())(())(())(())(())()()()()()(())(())(())()()(())(())(())()()(())()(())()()(())(())()()(())(())()()()(())(())(())(())(())()()(()(()))(())))

Try it online!

This probably isn't the optimal strategy (since it was the first one I thought of), but I've golfed this down enough that I feel confident posting it. I wrote a helper program to generate this program

(()) is a string re-writing scheme designed to only use parentheses. The top lines of Let x = (()) are to assign characters to the sets of parentheses so that input and output can make sense, but otherwise the entire program is that 3400 byte string at the bottom. Essentially it boils down to a series of string rewrite rules:

"e)" -> "large data string"
"LL" -| ""         (terminate on this substitution)
"L(" -> "()L"
"L)" -> "(())L"
"" -> "Initialisation (((()(()))(()))(Le)L))(((((()))((())))()))((((()))())(()(())((()))))((((()))(()))(()()(())(())((()))))((e)"

First we start with the input, which is empty. Only the last rule matches the empty string, so we replace the current string with the result from that:

Initialisation (((()(()))(()))(Le)L))(((((()))((())))()))((((()))())(()(())((()))))((((()))(()))(()()(())(())((()))))((e)

The first rule to match this string is the e) rule (which is constructed to avoid matching anything in the initialisation section). This matches twice, and we substitute the first and then the second, since none of the other rules before it apply:

Initialisation (((()(()))(()))(L large data string L))(((((()))((())))()))((((()))())(()(())((()))))((((()))(()))(()()(())(())((()))))(( large data string

The large data string is the parentheses representation of the original empty string substitution, which means that this is almost the final product, except that the first copy of data string needs to itself be translated to the parentheses version. We use the L( and L) rules to turn each character into it representation. Once we run out of those, the output looks like:

Initialisation (((()(()))(()))(large data string representation LL))(((((()))((())))()))((((()))())(()(())((()))))((((()))(()))(()()(())(())((()))))(( large data string

So we finally execute the LL rule, replacing LL with nothing and terminating the program.

\$\endgroup\$
2
\$\begingroup\$

*><>, 14 bytes

"#ooooooo;!-1:

Try it online!

*><> doesn't offer much more than its parent language ><> apart from file input and some new movement commands, neither of which are useful here. In fact, this is longer than the ><> quine, since *><> outputs the error to STDOUT, meaning we can't exit with an error.

Explanation:

"                   Wrapping string, pushing the code to the stack
 #                  Mirror, reverse directions
"                   Pushing the code to the stack in reverse
           -1:      Duplicate the top of the stack (#) and subtract one to get "
         ;!         Skip over the terminate
  ooooooo           Print seven characters
 #                  Mirror
  ooooooo           Print the other seven characters
         ;          And terminate
\$\endgroup\$
2
\$\begingroup\$

,,,, 15 bytes

"'%r:%%1⊢":%1⊢

Try it online!

Commata is a very underdeveloped golfing language. This makes use of the string formatting command to format the data with double quotes.

Explanation

"'%r:%%1⊢"       Push '%r:%%1⊢ to the stack
          :      Duplicate the string
           %     Format one string with the other
 '%r             Python's string repr with double quotes
            1⊢   And drop the leading '
\$\endgroup\$
2
\$\begingroup\$

ABC, 89 bytes

PUT {"0INa"; "1WRITE 'PUT',a"; "2FORbINa:WRITEb@2/"} INa
WRITE 'PUT',a
FORbINa:WRITEb@2/

Try it online!

This is one of those weird old languages, this one being "originally intended as a good replacement for BASIC". It has a few strange quirks, such as lists are iterated in sorted order, and you can only print newlines using a WRITE. At least the object to string conversion works well, and tokens can be placed right next to each other.

Explanation

PUT {"0INa"; 
     "1WRITE 'PUT',a"; 
     "2FORbINa:WRITEb@2/"}
INa                            Set a to the list of strings
WRITE 'PUT',a                  Print "PUT" and the list
FORbINa:                       Iterate over each string in the list
        WRITE                  Print
             b@2               The string excluding the first character
                /              And a newline

I don't think this ir quite optimal, but I think it's pretty close. You can't have a two line quine, since both lines would have to encode themselves, and I can't think of a way to do a one line quine.

\$\endgroup\$
2
\$\begingroup\$

Adapt, 19 bytes

`@96cs+.+`@96cs+.+

Try it online!

Explanation

`@96cs+.+`               Push string "@96cs+.+"
          @96            Push 96
             c           Convert it to the character "`"
              s+         Swap the two and concatenate "`@96cs+.+"
                .+       Duplicate and concatenate "`@96cs+.+`@96cs+.+"
                         Implicitly output
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Bloody hell, I had no idea Adapt was actually usable, that's super cool! \$\endgroup\$ Sep 21, 2020 at 11:01
2
\$\begingroup\$

Add++ -i, 14 bytes

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

Try it online!

Takes advantage of Python string formatting with the % command. Uses the -i flag to run the function without having to call it.

\$\endgroup\$
0
2
\$\begingroup\$

Labyrinth, 52 bytes

411096280599923751453245172184368156!
_
2/:@
" .
71_

Try it online!

Just beats out the previous Labyrinth quine by one byte, through using the modulo behaviour of ., and an unorthodox divisor.

Explanation:

This uses a similar setup to the other answer, but where that used a divmod of 98, this divides by 172 and modulos by 256. This first saves on the decoder section because the . instruction already moduloes by 256 before printing. But this alone isn't enough, so I started looking for a smaller divisor.

This is possible by brute-forcing the required number through rearranging the source code until it works, and only when the encoded string is really small (in this case 16 bytes). I wrote a Raku script to help brute force these variations of the code, with minor tweaks needed for different layouts.

The code itself is a simple loop

.....!  Push number and print it
.....   Then reverse direction, pushing the number in reverse

_       Enter the loop by
2/`     Integer dividing the initial number by 2
` `
```

``:     Duplicate and print value modulo 256
` .
```

2/`     Integer divide by 172
" `
71_

```@    If the division results in 0, terminate
` `
```

The above code ended up being one of my first attempts at this method, and I only ever found a couple of others that were the same size, this one and this one, both with divisor 172. I'm not sure why this is the magic number.

Some thoughts on further golfing through this method:

  • You can push 0 through ? or { (replacing _)
  • You can push 1 through # or ,` (replacing _1)
  • The wall in the center can be anything that isn't an instruction
  • " can be replaced with ' or some other no-op and can be placed pretty much anywhere in the loop

I'm honestly not sure if this format can be golfed. It seems unlikely that there's a format that supports a smaller divisor than 172, but then again, I'm not sure why 172 was an island of stability in the first place.

\$\endgroup\$
2
\$\begingroup\$

C (gcc), 70 bytes

#define a(b)*s=#b;b
a(main(){printf("#define a(b)*s=#b;b\na(%s)",s);})

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Assembly (NASM, 32-bit, Linux), 620 bytes

section .text
mov di,1
mov ebx,1
m:mov esi,a
l:mov ecx,esi
mov edx,1
mov al,[esi]
add ax,di
cmp al,10
jne p
mov ecx,b
mov dx,2
p:mov eax,4
int 128
mov al,[esi]
inc esi
cmp al,96
jne l
dec di
jz m
mov ecx,c
mov dx,3
mov ax,4
int 128
mov ax,1
int 128
section .data
c db 44,57,54
b db 92,110
a db`section .text\nmov di,1\nmov ebx,1\nm:mov esi,a\nl:mov ecx,esi\nmov edx,1\nmov al,[esi]\nadd ax,di\ncmp al,10\njne p\nmov ecx,b\nmov dx,2\np:mov eax,4\nint 128\nmov dl,[esi]\ninc esi\ncmp dl,34\njne l\ndec di\njz m\nmov ecx,c\nmov dx,3\nmov ax,4\nint 128\nmov ax,1\nint 128\nsection .data\nc db 44,57,54\nb db 92,110\na db`,96

-149 bytes by using backqoutes

-26 bytes by simplifying jumps

Try it online!

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

Swift 5, 202 bytes

While much longer than the shortest Swift submission, this has important aesthetic points for me since it avoids numerical ASCII references as well as any declarations at all, using an anonymous function, resulting in a single-statement solution.

import Foundation;({print($0+"("+String(data:try!JSONEncoder().encode($0),encoding:.utf8)!+")")})("import Foundation;({print($0+\"(\"+String(data:try!JSONEncoder().encode($0),encoding:.utf8)!+\")\")})")
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Welcome to the site! \$\endgroup\$ Nov 13, 2020 at 4:38
2
\$\begingroup\$

Setanta, 254 bytes

s:="s:=?q:='\"'n:=cuid@s(0,9)o:=cuid@s(9,fad@s)scriobh(athchuir@n(\"?\",q+athchuir@(athchuir@s(\"\\\\\",\"\\\\\\\\\"))('\"','\\\\\"')+q)+o)"q:='"'n:=cuid@s(0,9)o:=cuid@s(9,fad@s)scriobh(athchuir@n("?",q+athchuir@(athchuir@s("\\","\\\\"))('"','\\"')+q)+o)

Try it here!

This was pretty long, mainly because Setanta doesn't have any string formatting builtins. Probably could still be improved.

Edit 2021/2/4: It seems that you now need to spell the function to print a value as scríobh (previously, you could use scriobh without the accent on the i). Making that fix adds 2 bytes to the solution.

\$\endgroup\$
2
\$\begingroup\$

Perl 5, 24 bytes

print<<""x2
print<<""x2

24 bytes without any options.

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Perl 5, 38 bytes

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

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Adjust, 21 bytes

`@96c$+.+O`@96c$+.+O

Try it online!

Basically just a port of the Adapt quine, but updated with Adjust's swap command ($ vs Adapt's s) and no longer implicit output

\$\endgroup\$
2
\$\begingroup\$

AWK, 56 bytes

BEGIN{printf a="BEGIN{printf a=%c%s%c,34,a,34}",34,a,34}

Try it online!

Outgolfed these two.

\$\endgroup\$
2
\$\begingroup\$

Python 3, 48 bytes

s='print(f"s={s!r};{s}")';print(f"s={s!r};{s}")

Try it online!

Python 3, 74 bytes

s=r"s=;print(f'{s[:2]}r\"{s}\"{s[2:]}')";print(f'{s[:2]}r\"{s}\"{s[2:]}')

Try it online!

First two attempts... I think this is the basic approach, just used Python's f-strings.

\$\endgroup\$
2
\$\begingroup\$

05AB1E, 13 bytes

"34çì«"34çì«

Try it online!

"..."34çì«  # trimmed program
"..."       # push literal...
        ì   # prepended with...
       ç    # character with codepoint...
     34     # literal...
         «  # concatenated with...
            # (implicit) itself
            # implicit output
\$\endgroup\$
2
\$\begingroup\$

Pxem Pxem (esolang-box notation), 162 113 109 bytes.

Eventually as in meta discussion I had to change the language. The following program equals to filename with same name and empty content in original notation.

Be!?BzBc!!B+BzXXFBaBcFBzBsXXFBBaBsBtBvBmBvBcAcB-BaBsBp".e!?.z.c!!.+.zXXF.a.cF.z.sXXF..a.s.t.v.m.v.cAc.-.a.s.p

Try it online!

With comments

XX.z
# represents programs from first .m
# every dot has to be replaced with B, for example,
# because dots are syntaxically special
# append " to it
.aXX(long)".z
# essentially double entire stack
.a.eXX.z
# loop begin
.a!?.zXX.z
  # move every character to bottom
  # HOWEVER B is replaced with DOT
  # when exiting from loop, the stack will be:
  # "(original data)"(modified data)
  #
  # push dummy F if B is not top
  .a.c!!.+.zXXF.aXX.z
  # replace B with dot, and push F if F is not top
  .a.cF.z.sXXF..aXX.z
  # remove dummy
  .a.sXX.z
  # move to bottom
  .a.t.v.m.vXX.z
# get out if "
.a.cAc.-.aXX.z
# finally; discard top
.a.s.p

Previous version

  • 113 bytes: Bm!?BzBcBoBc!!B+BzXXFBaBcFBzBsXXFBBaBsBtBvBmBvBcAcB-BaBp".m!?.z.c.o.c!!.+.zXXF.a.cF.z.sXXF..a.s.t.v.m.v.cAc.-.a.p
  • 162 bytes: XXx\è\ô\Ú\î\Ú\Þ\Ú\Þ\Ú@\V\Þ``\Z\Â\Æ\Æ\Þ\è\ì\Ú\ì``\Z\è¢\Â\ì\æ\ì°\î\Æ\Æ\ô\È\Â\H\Þ°\ÂQ.t.z.m.w.m.o.m.o.m .+.o00.-.a.c.c.o.t.v.m.v00.-.tQ.a.v.s.vX.w.c.c.z.d.a.$.oX.a
\$\endgroup\$
7
  • \$\begingroup\$ This isn't a quine. It's a program that outputs its own file name. A quine would require the filename to not be important; which I'm not sure is possible in Pxem. This is like submitting a 35 byte Python solution with code exec(__file__)\n with filename print'exec(__file__)': TIO. Even though this is not in direct violation of any rules here, it clearly breaks their spirit. But what you're doing here is against the rules. \$\endgroup\$
    – Makonede
    May 29, 2021 at 21:35
  • \$\begingroup\$ @Makonede but Pxem matters filename first and content is matter if and only if .f and .e are in filename; would I just undo frilom 109-byte version to 113-byte version to remove .e? Or should have I just clarify that a Pxem program consists of filename and optionally its content? In this case I would claim that its filename is the only source code; then I would satisfy the definition of quine: produces a copy of its own source code. \$\endgroup\$
    – user100411
    May 29, 2021 at 23:32
  • \$\begingroup\$ A Pxem program may run based on filename, but that does not automatically make it need to output its code instead of its content. A quine is still a quine, no matter how a language is implemented. Remember that you can't just make it output its content, by the way. A quine has to have part of its code that encodes the entire program. And even though I originally thought this isn't breaking rules, I'm 99.9% sure this is a rule somewhere, I just can't describe it in search-friendly keywords. I'll ask TNB about this answer for their opinion, I'm highly doubtful that this is a valid answer. \$\endgroup\$
    – Makonede
    May 30, 2021 at 3:18
  • \$\begingroup\$ @Makonede; the programs output their filenames; not content. \$\endgroup\$
    – user100411
    May 30, 2021 at 3:26
  • \$\begingroup\$ Or should the 109-bytes version be represented in plain-text notation, such as in esolang-box or nk.'s text2pxem.pl? \$\endgroup\$
    – user100411
    May 30, 2021 at 22:18
2
\$\begingroup\$

Agda, 160 bytes

open import IO;open import Data.String;main = run(putStr(r ++ show r))where r ="open import IO;open import Data.String;main = run(putStr(r ++ show r))where r ="

Try it online!

Agda is an interesting Haskell-like language with some interesting ideas and a lot of imports. Luckily I've managed to avoid most of those (though my early attempts weren't so successful). The version on TIO is a bit out of date, which led to some frustration with the docs, but I think this code should still work with the latest version.

Explanation:

open import IO           -- Import the IO library for `run` and `putStr`
open import Data.String  -- Import Data.String for `++` and `show`
main = run(putStr        -- with main, print the string
       (r ++ show r))    -- r appended with the string representation of r
       where r =         -- where r is
                 "..."   -- the string of the rest of the program
\$\endgroup\$
2
\$\begingroup\$

OCaml, 66 bytes

(fun x->Printf.printf"%s%S"x x)"(fun x->Printf.printf\"%s%S\"x x)"

Try it online!

\$\endgroup\$
1
9 10
11
12 13
15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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