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

2
\$\begingroup\$

Nim, 95 bytes

import strutils;let s="import strutils;let s=$#;echo s%s.repr[^49..^1]";echo s%s.repr[^49..^1]

Try it online!

After scrolling through the leaderboard snippet, I was surprised to see that Nim hasn't been represented here yet. So, let's fix it!

This follows the standard pattern of constructing and printing a string with a quoted representation of itself inserted in the middle. Unfortunately, Nim has a few features that make this golf-unfriendly:

  • String interpolation with % is not available unless you import strutils.
  • repr not only quotes strings, but also prepends them with a hex number (seemingly, memory address), like this: 0x40a6d0"my string". Therefore, we have to extract the right part.

Still, not so bad overall, as it is significantly shorter than the version currently posted at Rosetta Code, which actually doesn't even work without tweaks in recent versions of the language.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ var x="var x=;echo x[0..5],x.repr[14..^1],x[6..^1]";echo x[0..5],x.repr[14..^1],x[6..^1] \$\endgroup\$ – ASCII-only Aug 27 '19 at 3:25
2
\$\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

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

Cardinal, 10 bytes

",-#) %8-$

Try it online!

This should be a quine, except for a small bug in the interpreter which causes the ( command to throw an error. For completeness' sake, here's a version where a # is placed in the position the ( is accidentally calling. Note that the space is actually a NUL character. Bug is fixed, yay!

"% (#-,0-$ also works with just one pointer.

How It Works:

The % creates two pointers, going left and right (the ones going vertical don't matter). The right pointer is delayed by the 8 for three steps, which lets the left pointer execute ,-#) which changes the active value to #, decrements it and prints the ". Then the right pointer starts again, decrementing the active value to -1. $ sets the pointer location to 0,-1, which then runs " over the rest of the code, printing it.

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ You can download fixed and recompiled version (including source code) of the interpreter from my Github repo: github.com/m-lohmann/Cardinal. The original interpreter had several errors that needed fixing. \$\endgroup\$ – M L Jun 2 '18 at 0:08
  • \$\begingroup\$ I don't think your last edit worked properly, the URLs are identical. \$\endgroup\$ – Ørjan Johansen Sep 5 '18 at 18:11
  • \$\begingroup\$ @Orjan lol, it seems I had already made the exact change in a previous edit. \$\endgroup\$ – Jo King Sep 7 '18 at 13:30
2
\$\begingroup\$

Backhand, 21 bytes

"#v{<@^:[ba+0v|{$:o[}

Try it online!

This is my new 1D language Backhand. It's a little bit more complicated than the typical wrapping string literal quine.

Explanation:

The program initially starts with a step count of 3.

"      Start string literal, stepping 3 places at a time
       This pushes the source code, but all jumbled up :(

See my Hello, World! answer to see what you have to do to push a string normally.

"      End the garbage string literal
  v{   Step left and decrease the step count to 2
    <  Change direction to left
  v    Decrease the step count to 1
 #     No-op
"      Start string literal
       Now the step count is 1, so it actually pushes the source code
 #v{<@^:[ba+0v|{$:o[}    Push to stack going right and bounce off the end
 #v{<@^:[ba+0v|{$:o[     Push to stack going left
"      End string literal
  v    Decrease the step count to 0
  v    Decrease the step count to -1
       Now the pointer is technically going right, but with a step count of -1
"      Push the source code again...
  v    Decrease the step count to -2
    <  Change direction to left (step count is still negative, so it goes right)

      ^           Increase step count to -1
       :[         Dupe the top of stack (# 35) and decrement to 34 (")
         ba+      Add 10 and 11 to push 21 as the counter
            0     Push 0
             v    Decrease step count to -2
               {  Step left
              |   Pop 0 and continue moving left
                $ o    Swap the top two items and print the character
                   [}  Step right (against the wall so it bounces) and decrement the counter
              |{ :     Duplicate the counter and reflect if it is non-zero
                       Repeat this 21 times to print the source code
        [ a 0  Garbage
      ^        Increase the step counter to -1
     @         Terminate program
| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

Elixir, 44 bytes

q=:'q=:~p;:io.format q,[q]';:io.format q,[q]

Try it online!

This is basically an existing quine taken from here, but I managed to save another 2 bytes by declaring q as an atom instead of a binary.

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

Clean, 123 102 bytes

module q;import StdEnv;Start=(s,q,s,q);q=inc'!';s="module q;import StdEnv;Start=(s,q,s,q);q=inc'!';s="

Save as q.icl and compile with -b -nt.

Saved 21 bytes thanks to Οurous.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ This can be improved to 102: module q;import StdEnv;Start=(s,q,s,q);q=inc'!';s="module q;import StdEnv;Start=(s,q,s,q);q=inc'!';s=" \$\endgroup\$ – Οurous Feb 13 '19 at 7:09
  • \$\begingroup\$ @Οurous nice idea, thanks. \$\endgroup\$ – user42682 Feb 13 '19 at 8:36
2
\$\begingroup\$

Java, 515 bytes

In order to make this quine, I made strings representing every part of the code that needed to be printed. Then, I created and printed a string representing the code by adding the strings together.

This is my first time playing code golf, let me know what you think of my quine!

interface a{static void main(String[]a){String ce="interface a{static void main(String[]a){String ",e="=",c="\",",q="\"",cq="\\",ec=";System.out.print(ce+cc+ee+e+q+ce+c+ee+e+q+e+c+cc+e+q+cq+c+c+qq+e+q+cq+q+c+cc+qq+e+q+cq+cq+c+ee+cc+e+q+ec+c+ee+qq+e+q+eq+c+ee+ee+e+q+ee+c+cc+cc+e+q+cc+c+qq+qq+e+q+qq+q+ec+eq",eq=");}}",ee="e",cc="c",qq="q";System.out.print(ce+cc+ee+e+q+ce+c+ee+e+q+e+c+cc+e+q+cq+c+c+qq+e+q+cq+q+c+cc+qq+e+q+cq+cq+c+ee+cc+e+q+ec+c+ee+qq+e+q+eq+c+ee+ee+e+q+ee+c+cc+cc+e+q+cc+c+qq+qq+e+q+qq+q+ec+eq);}}

in readable form:

interface a
{
    static void main(String[] a)
    {
        String ce = "interface a{static void main(String[]a){String ",
            e = "=",
            c = "\",",
            q = "\"",
            cq = "\\",
            ec = ";System.out.print(ce+cc+ee+e+q+ce+c+ee+e+q+e+c+cc+e+q+cq+c+c+qq+e+q+cq+q+c+cc+qq+e+q+cq+cq+c+ee+cc+e+q+ec+c+ee+qq+e+q+eq+c+ee+ee+e+q+ee+c+cc+cc+e+q+cc+c+qq+qq+e+q+qq+q+ec+eq",
            eq = ");}}",
            ee = "e",
            cc = "c",
            qq = "q";
        System.out.print(ce+cc+ee+e+q+ce+c+ee+e+q+e+c+cc+e+q+cq+c+c+qq+e+q+cq+q+c+cc+qq+e+q+cq+cq+c+ee+cc+e+q+ec+c+ee+qq+e+q+eq+c+ee+ee+e+q+ee+c+cc+cc+e+q+cc+c+qq+qq+e+q+qq+q+ec+eq);
    }
}
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ If you want to try shortening this further, have a look into using the printf function \$\endgroup\$ – Jo King Jun 28 '19 at 6:41
  • \$\begingroup\$ I tried that, but I found print easier. I guess I'll try again. \$\endgroup\$ – Ethan Gallagher Jul 1 '19 at 2:22
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)
| improve this answer | |
\$\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
| improve this answer | |
\$\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.

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

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Unless Poetic uses a custom code page/encoding, this is actually 3312 bytes as ÿ is 2 bytes in TUF-8 \$\endgroup\$ – caird coinheringaahing 2 days ago
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
| improve this answer | |
\$\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:++:+:++:+:++:+++?
| improve this answer | |
\$\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.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Nice answer! I have edited in a link to the online interpreter, in case people want to test out your code. \$\endgroup\$ – Surculose Sputum Jun 1 at 10:48
  • 1
    \$\begingroup\$ You can save a few bytes by removing the redundant spaces. Try it online! \$\endgroup\$ – Surculose Sputum Jun 1 at 10:54
  • \$\begingroup\$ Right, thanks for that little optimization \$\endgroup\$ – Smiley1000 Jun 1 at 20:08
2
\$\begingroup\$

R, 44 42 bytes

crossed out 44 is still regular 44 ;(

-2 bytes thanks to Dominic van Essen

Works on R Version 3.6.2 and greater (thanks to Giuseppe for figuring out the versions).

f <-
function()cat(dump("f",""),"()")
f ()

Try it online!

This is 3 5 bytes shorter than the previous shortest quine by JAD.

Note that TIO currently uses R version 3.5.2, and thus adds some spaces and newlines to the output, but my local install of R version 3.6.3 does not, and gives the exact correct output.

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ IIRC TIO calls R by using Rscript as seen here, not sure if that's the difference. \$\endgroup\$ – Giuseppe Aug 4 at 15:48
  • \$\begingroup\$ Nice! And you can even shed 2 more bytes to 42 bytes (also works on R installation but not properly on TIO or RScript). \$\endgroup\$ – Dominic van Essen Aug 4 at 17:51
  • \$\begingroup\$ @DominicvanEssen Neat, thanks! \$\endgroup\$ – Robin Ryder Aug 4 at 21:46
  • \$\begingroup\$ Some digging in R news shows that since TIO's R install (3.5.2), there's been a change to dump as of version 3.6.2: see this edition of R News. I have 3.6.1 on my machine and it prints the function() and its body on separate lines. \$\endgroup\$ – Giuseppe Aug 4 at 22:03
  • \$\begingroup\$ @Giuseppe Thanks for working that out! \$\endgroup\$ – Robin Ryder Aug 5 at 5:39
1
\$\begingroup\$

Groovy:

`s='s=\\\';s[0..1]+s[3]+s[0..1]+s[2]*6+s[3..-1]*2';s[0..1]+s[3]+s[0..1]+s[2]*6+s[3..-1]*`2

Edit

Works in GroovyConsole

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

C, 125 84 chars

main(){char*p="main(){char*p=%c%s%c,c='%c',s[256];sprintf(s,p,c,p,c,c);puts(s);}",c='"',s[256];sprintf(s,p,c,p,c,c);puts(s);}

It turns out that my idea was implemented much better:

main(){char*p="main(){char*p=%c%s%c;printf(p,34,p,34,10);}%c";printf(p,34,p,34,10);}
| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ You could shave 9 chars off the shorter version by leaving out the trailing newline. \$\endgroup\$ – Ilmari Karonen Feb 3 '12 at 18:55
1
\$\begingroup\$

F♯# - 349 Characters

let s="\\\"\nnlet s=let z a b=s.Substring(a,b)System.Console.WriteLine()z 4 6+z 1 1+z 0 1+z 0 1+z 0 1+z 1 1+z 0 1+z 3 1+z 3 1+z 4 169+z 1 1+z 2 1+z 10 26+z 2 1+z 36 25+z 62 111+z 61 1" 
let z a b=s.Substring(a,b)
System.Console.WriteLine(z 4 6+z 1 1+z 0 1+z 0 1+z 0 1+z 1 1+z 0 1+z 3 1+z 3 1+z 4 169+z 1 1+z 2 1+z 10 26+z 2 1+z 36 25+z 62 111+z 61 1)

My first attempt at a quine - probably an easier (or shorter) way to do it, but not a bad first attempt I don't think

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

Tcl, 61 chars

set c {set c {$c};puts [subst -noc \$c]};puts [subst -noc $c]
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Erlang escript 225 164 140

$ escript quine

main(_)->[A|B]=["main(_)->[A|B]=[","],io:put_chars([10,A,34,A,34,44,34,B,34,B,10,10])."],io:put_chars([10,A,34,A,34,44,34,B,34,B,10,10]).

$

Apparently escript has to have at least three lines.

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

Go - 583

Just because d;

package main
import "fmt"
func main(){
    a := string(byte(34))
    b := []string{
        "package main",
        "import fmt",
        "func main(){",
        "   a := string(byte(34))",
        "   b := []string{",
        "       ",
        "   }",
        "   for i:=0;i<5;i++{if i != 1{fmt.Println(b[i])}else{fmt.Println(b[i][:7]+a+b[i][7:]+a)}}",
        "   for _,v:=range b{fmt.Println(b[6]+a+v+a+string(','))}",
        "   for i:=7;i<9;i++{fmt.Println(b[i])}",
        "}",
        }
    for i:=0;i<5;i++{if i != 1{fmt.Println(b[i])}else{fmt.Println(b[i][:7]+a+b[i][7:]+a)}}
    for _,v:=range b{fmt.Println(b[5]+a+v+a+string(','))}
    for i:=7;i<11;i++{fmt.Println(b[i])}
}
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ this is awesome. \$\endgroup\$ – cat Dec 7 '15 at 14:50
1
\$\begingroup\$

Cobra - 143

class P
    def main
        s='class P{2}   def main{2}     s={1}{0}{1}{2}      Console.write(s,s,39to char,10to char)'
        Console.write(s,s,39to char,10to char)
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Lua, 76 characters

s="s=%c%s%c;print(string.format(s,34,s,34))";print(string.format(s,34,s,34))

Another one with the usual format string technique.

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

Julia, 101 characters

s="s=%c%s%c;@printf %c%s%c 34 s 34 34 s 34";@printf "s=%c%s%c;@printf %c%s%c 34 s 34" 34 s 34 34 s 34

It's the usual format string technique, but unfortunately you can't get the format specification string from a variable in Julia, so I have to include it twice in the code, which blows everything up.

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

Minkolang 0.9, 10 bytes

This language was made after this challenge, but was not made for it.

"66*2-(O).

Like other 2D languages, the " makes everything between it and the next " a string. 66*2- adds the not-included " and (O). prints everything out and stops.

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

Scala, 84 bytes

val d="""
print("val d=\"\"\""+d+"\"\"\""+d)
"""
print("val d=\"\"\""+d+"\"\"\""+d)

Kinda straightforward, but putting it out there for completion.

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

Seriously, 2 bytes

1

Pushes the number 1, implicit print with trailing newline. Since this is fairly trivial, here is the smallest non-trivial quine which can contain arbitrary characters (12 bytes):

`è";ƒ"@+`;ƒ

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

Python 3 - 58 Characters

Since there is a Python 2 version, I suppose this is acceptable:

x='x={};print(x.format(repr(x)))';print(x.format(repr(x)))
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Java, 190 Characters

class I{public static void main(String[]a){String s="class I{public static void main(String[]a){String s=%c%s%1$c;System.out.print(s.format(s,34,s));}}";System.out.print(s.format(s,34,s));}}
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Since ye olde Java SE 8, you can put static methods (such as main) in interfaces - no public. Also print and format methods can be collapsed into printf. \$\endgroup\$ – Tom Hawtin - tackline Oct 6 '18 at 23:08
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\$

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.