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

322 Answers 322

4
\$\begingroup\$

Taxi, 1144 1034 970 bytes

"is waiting at Writer's Depot.34 is waiting at Starchild Numerology.Go to Starchild Numerology:w 1 r 3 l 2 l 3 l 2 r.Pickup a passenger going to Charboil Grill.Go to Charboil Grill:e 1 l.Pickup a passenger going to KonKat's.Go to Writer's Depot:w 1 r.Pickup a passenger going to KonKat's.Go to KonKat's:n 3 r 2 r.Pickup a passenger going to Cyclone.Go to Cyclone:n 1 l 2 l.Pickup a passenger going to Post Office.Pickup a passenger going to Post Office.Go to Post Office:s 1 l 2 r 1 l."is waiting at Writer's Depot.34 is waiting at Starchild Numerology.Go to Starchild Numerology:w 1 r 3 l 2 l 3 l 2 r.Pickup a passenger going to Charboil Grill.Go to Charboil Grill:e 1 l.Pickup a passenger going to KonKat's.Go to Writer's Depot:w 1 r.Pickup a passenger going to KonKat's.Go to KonKat's:n 3 r 2 r.Pickup a passenger going to Cyclone.Go to Cyclone:n 1 l 2 l.Pickup a passenger going to Post Office.Pickup a passenger going to Post Office.Go to Post Office:s 1 l 2 r 1 l.

Please ignore the output to stderr. Who needs a job if you can quine anyway?

Try it online!

How does this work?

Short answer

This quine starts with a string. If you replace the content of that string by <string>, the code looks like "<string>"<string>, which is "<string> twice. Because the string doesn't contain the double quote, we first get the double quote via its character code, concatenate it with the string, then copy the string and concatenate it with itself. Finally, we print the string.

Long answer

under construction

\$\endgroup\$
4
\$\begingroup\$

tinylisp, 88 bytes

The byte count includes a trailing newline.

((q (g (c (c (q q) g) (c (c (q q) g) ())))) (q (g (c (c (q q) g) (c (c (q q) g) ())))))

Try it online!

There are no strings in tinylisp, but a nontrivial quine is still possible because code is lists and lists are code. The above code is a list which, when evaluated, returns (and therefore prints) itself.

The idea is to pass the list (g (c (c (q q) g) (c (c (q q) g) ()))) to a function which will wrap it in a list, tack a q on the front, and then wrap two copies of that in a list. Which is exactly what the function (q (g (c (c (q q) g) (c (c (q q) g) ())))) does. In-depth explanation available on request, but I wanted to post this before turning in for the night.

\$\endgroup\$
4
\$\begingroup\$

Operation Flashpoint scripting language,  22  15 bytes

q={"q={"+q+"}"}

Call with:

hint call q

Output:

q={"q={"+q+"}"}

Old version (22 bytes):

q={format["q={%1}",q]}
\$\endgroup\$
4
\$\begingroup\$

Underload, 10 Bytes

(:aSS):aSS

Try it online!

\$\endgroup\$
4
\$\begingroup\$

JavaScript, 53 bytes

A quine without any uses of uneval or Function.prototype.toString.

Q="q=Q.link()[8];alert(`Q=${q+Q+q};eval(Q)`)";eval(Q)

Can avoid use of template strings for + 1 byte.

Q="q=Q.link()[8];alert('Q='+q+Q+q+';eval(Q)')";eval(Q)


JavaScript, 74 bytes

Another approach avoiding uneval and Function.prototype.toString:

console.log(a="console.log(a=%s%s%s,q=a.link()[8],a,q)",q=a.link()[8],a,q)

\$\endgroup\$
4
+400
\$\begingroup\$

Pain-Flak, 2009 bytes

><))(())(())()(())(())()(())(())(())(())()()(())()(())(())()()()(())(())()(())(())()()(())(())(())()(())(())()()(())(())(())()(())(())()(())(())()(())(())()(())()(())()(())()(())()(())(())(())()()(())()()(())(())(())()()(())(())(())()()()(())(())(())()()()(())(())()()(())()(())()()(())(())()()()(())(())(())(())(())(())()(())()()()(())()(())()()(())(())()()()(())(())(())()()()(())(())()()(())()(())(())()()(())()()(())(())(())()()(())(())(())(())(())(())()()()(())(())(())()()(())(())(())(())()()(())()()(())()()()(())(())()()(())()(())(())()()(())(())(())(())(())(())()()(())()()()(())(())()(())(())()()(())()(())()()(())()()()(())(())()()(())(())(())(())(())(())()()(())()()()(())()(())(())()(())()()(())(())()(())()()()()(())()(())(())(())(())(())(())(())(())()(())(())(())()()(())()(())(())(())(())(())()()()(())()(())(())()()(())(())(())()()(())()(())(())(())()()(())()(())()(())(())(())(())()()(())()(())()()()()(())()(())()(())()()()(())(())(())()(())(())()()(())(())(())()()(())()(())(())(())()()(())()(())()(())(())(())()()(())(())(())()(())(())()(())(())()(())(())()(())(())()(())()(())()(())()(())()()()(())(())()(())(())()()(())()(())()(())()()()(())()(())(())(())()(())()()()()(())()()(())(())()(())()(())(())(())(())()()(())(())(())()()()(())(())(())()()()(())(())()()(())()(())()()(())(())()()()(())(())(())()()()(())(())(())(())()(())(())(())(())()(())()()()()(())(())()()(())()(())()(())()(())(())()()()(())(())(())()(())(())()()(())()(())()()(())()()()(())(())()(())(())(())(())()()(())()()()()(())()(())()(())(())()()()(())(())(())()(())(())(())()()(())(())(())()()(())(())(())()()(())(())(())()(())(())()(())(())()(())(())()(())(())()(())()(())()(())()(())()(())()(())(())()()()(())()()((}><))))))()()()()((}{(}{(}{()((><))]}{[()(>})}{)((><)))}{])([()(((><{><})}{><(><{}{<())(}])([)>))}{)(>))))()()()()((}{())}{()}{(}{)((>))])}{([))}{()}{(}{)><((()}{()((<(<(()])(})()>}{<({[}{>})}{)(>}{<({<}{)}{>}}{{<}{(><(<({}{(}}{)}{><(><})>)(<({{><})}{><(><{}{{}}{{)))))()()()((}{)((}{)(><)}{(()()((

Try it online!

(Trailing newline because the interpreter outputs a newline.)

-176 bytes by improving the Brain-Flak quine

Basically a straight port of my Brain-Flak quine. The only major difference is the >< at the beginning, which is required in order to keep the data section out of the output.

><                 switch to right stack; effectively does nothing since both stacks are empty
))((...))()()((    data, same format as the Brain-Flak quine
}main loop{        same as the Brain-Flak quine, but with different constants
}}{{               clear current stack; this does nothing
)))))()()()((}{)((}{)(><)}{(()()((   push opening >< at beginning of code

Since this is Pain-Flak, the code also goes backward after it is finished going forward. As such, I had to ensure that this does not mess up the output.

))()())}{(><)(}{))(}{))()()()(((((   push 70, 68, 5, 4 on right stack
}}{{               clear right stack
}pool niam{        do nothing because top of stack is zero
))()()((...))((    push constants on right stack in reverse order
><                 switch to left stack and implicitly output
\$\endgroup\$
  • 1
    \$\begingroup\$ The only Pain-Flak solutions I've seen are ones directly translated from Brain-Flak... \$\endgroup\$ – Jo King Apr 10 '18 at 5:21
  • \$\begingroup\$ I will give the bounty but kinda lame that it is just a port \$\endgroup\$ – Christopher Apr 25 '18 at 10:39
  • \$\begingroup\$ @Christopher it is your fault that you made Pain-Flak so similar to Brain-Flak :P \$\endgroup\$ – ASCII-only Apr 30 '18 at 22:13
  • \$\begingroup\$ @ascii painflak update is removing swap stack \$\endgroup\$ – Christopher Apr 30 '18 at 22:47
  • \$\begingroup\$ @Christopher then it'll just be translated Mini-flak? \$\endgroup\$ – ASCII-only Apr 30 '18 at 23:09
4
\$\begingroup\$

Reflections, 9228 bytes

As the program has 8620 lines, I won't put it here completely.

First line:

\

Then, for each character in the last part (below), there are n newlines for ASCII character n, followed by:

+
#

After it, the last part is (the # is actually already covered by the previous section):

#  /  \          /+\  /#_=0v\
>~ <       /(1:1)#@/       ~
\(0/      2)     \3)(2:2)(3^ 0#+#@
           \:(24):(4#_#_#_  /
      +               \*             (4\
      \*(1(2                          +/

Test it!

Working on explanation.

I had to fix a bug in the interpreter for this one. Does that count as adding a feature just for a challenge?

\$\endgroup\$
  • 1
    \$\begingroup\$ :| the URL encoding format is terrible \$\endgroup\$ – ASCII-only May 22 '18 at 0:57
4
\$\begingroup\$

2DFuck, 1352 1289 bytes

!xv>>>>x>x>>>>>>x>x>x>x>>x>x>x>>x>x>>x>x>x>x>x>>x>x>>x>x>>x>x>x>x>x>>x>x>x>x>x>>x>x>x>x>>x>x>>x>x>x>>x>x>>x>>>x>>>>>>x>>>>>x>>x>>>x>x>>x>>>x>>>>>>x>x>x>>>>>x>>>x>>>x>x>>x>x>x>x>x>>x>x>x>x>>>x>x>x>x>>x>x>x>x>x>x>>x>x>>>>>>>>>>x>x>>>>>x>>x>>>x>x>>x>>>x>>>>>>x>>>>>x>>x>>>x>x>>x>>>x>>>>>>x>x>x>>>>>x>>>x>>>x>x>x>>x>x>>x>x>>x>x>x>x>>x>x>>>x>x>>>>x>>x>>>x>>>>>>>>>>x>>>x>>>x>x>x>>x>x>>x>x>x>x>x>>x>x>>x>>>x>x>>>>x>>x>>>x>>>>>>>>>>x>>>x>>>>>>>>>>x>>>x>>>x>x>>x>x>>x>x>>x>x>x>x>>x>x>>x>x>>x>>>x>x>>>>x>>x>>>x>>>x>x>>x>x>>x>x>>x>x>x>>x>x>>x>x>x>>x>>>x>x>>>>>x>>>>x>x>>>>x>>x>>>x>>>>>>>>>>x>>>x>>>x>x>>x>x>x>x>>x>x>x>>x>x>>x>x>>>x>x>>>>x>>x>>>x>>>>>>>>>>x>>x>>>x>>>x>x>x>>x>x>x>x>x>x>>x>x>>>x>x>>>>x>>>x>>>>>>>>>>x>>x>>>x>>>x>x>x>>x>x>x>x>x>>x>x>x>>>x>x>>>>x>>>x>>>>>>>>>>x>>x>>>x>>>x>x>>x>x>>x>x>>x>x>x>x>x>>x>x>>>x>x>>>>x>>>x>>>>>>>>>>x>>>x>>>x>x>>x>x>x>x>x>>x>x>x>x>>>x>x>>>>x>>x>>>x>>>x>x>>x>x>x>x>>x>x>>x>x>x>>x>x>>>x>x>>>x>x>>>x>x>>>x>x>>>x>x>>>>>x>>>>x>x>>>>>>>>x>x>>>x>x>>>>>>>>>>x>x>>>>>x>>x>>>x>x>^x!..!.!....!.!.!....!....!...!.!..!.![<r!]![vr[!.!....!...]..!.....!.>^r!]![<r!]![vr[!..!.!.!...!.]r![>r[!..!.!....!.!]r![>r[>r[!.!.!.!...!.!.!]r![!.!.!.!..!.!..!]<]r![>r[!.!...!..!.!.]r![>r![!..!.....!.]r[>r![!..!....!..]r[>r![!.!.!.!....!.]r[>r[!.!....!...]r![!.!...!.!..!.]]]]]<]>]]>^r!]

Try it online!

Shaved off 63 bytes with Huffman coding! New explanation in progress.

\$\endgroup\$
4
\$\begingroup\$

Z80Golf, 120 bytes

00000000: 21f5 76e5 2180 10e5 21cd 00e5 2180 7ce5  !.v.!...!...!.|.
00000010: 21cd 00e5 21e1 7de5 2106 14e5 2110 e8e5  !...!.}.!...!...
00000020: 2100 80e5 21e5 cde5 211b 3ee5 2100 80e5  !...!...!.>.!...
00000030: 211a cde5 2180 13e5 21cd 00e5 211b 1ae5  !...!...!...!...
00000040: 2180 1be5 21cd 00e5 213e 21e5 2106 14e5  !...!...!>!.!...
00000050: 0614 3e21 cd00 801b 1b1a cd00 8013 1acd  ..>!............
00000060: 0080 1b3e e5cd 0080 10e8 0614 e17d cd00  ...>.........}..
00000070: 807c cd00 8010 f576                      .|.....v

Try it online!

Verification:

$ ./z80golf a.bin | xxd
00000000: 21f5 76e5 2180 10e5 21cd 00e5 2180 7ce5  !.v.!...!...!.|.
00000010: 21cd 00e5 21e1 7de5 2106 14e5 2110 e8e5  !...!.}.!...!...
00000020: 2100 80e5 21e5 cde5 211b 3ee5 2100 80e5  !...!...!.>.!...
00000030: 211a cde5 2180 13e5 21cd 00e5 211b 1ae5  !...!...!...!...
00000040: 2180 1be5 21cd 00e5 213e 21e5 2106 14e5  !...!...!>!.!...
00000050: 0614 3e21 cd00 801b 1b1a cd00 8013 1acd  ..>!............
00000060: 0080 1b3e e5cd 0080 10e8 0614 e17d cd00  ...>.........}..
00000070: 807c cd00 8010 f576                      .|.....v

$ ./z80golf a.bin | diff -s a.bin -
Files a.bin and - are identical

Looks like no one tried to make a proper quine in machine code yet, so here is one.

Although the machine code is loaded to memory, it does NOT read any address occupied by the code. Instead, it uses the stack space to setup required data.

Disassembly

start:
  ld hl, $76f5
  push hl
  ld hl, $1080
  push hl
  ld hl, $00cd
  push hl
  ld hl, $7c80
  push hl
  ld hl, $00cd
  push hl
  ld hl, $7de1
  push hl
  ld hl, $1406
  push hl
  ld hl, $e810
  push hl
  ld hl, $8000
  push hl
  ld hl, $cde5
  push hl
  ld hl, $3e1b
  push hl
  ld hl, $8000
  push hl
  ld hl, $cd1a
  push hl
  ld hl, $1380
  push hl
  ld hl, $00cd
  push hl
  ld hl, $1a1b
  push hl
  ld hl, $1b80
  push hl
  ld hl, $00cd
  push hl
  ld hl, $213e
  push hl
  ld hl, $1406
  push hl

  ld b, 20
loop1:
  ld a, $21
  call $8000
  dec de
  dec de
  ld a, (de)
  call $8000
  inc de
  ld a, (de)
  call $8000
  dec de
  ld a, $e5
  call $8000
  djnz loop1

  ld b, 20
loop2:
  pop hl
  ld a, l
  call $8000
  ld a, h
  call $8000
  djnz loop2

  halt

At start, the stack pointer sp is zero, just like other registers. Pushing some values causes sp to decrease, so the values are stacked in the memory region $ffxx.

The combination ld hl, $xxxx and push hl seems like the best option to dump predefined values into some memory space. It takes 4 bytes to store 2 bytes; any other option I could think of uses 3 or more bytes to store only one byte.

The first loop prints the ld hl, $xxxx (21 xx xx) and push hl (e5) instructions for the data, from the bottom of the stack (the address, represented by de, is decreased starting from $0000).

ld b, $xx and djnz label combined forms a fixed-times looping construct. It is only 4 bytes, which is optimal in Z80 (unless the loop count is already saved in another register).

But there is an endianness problem here, so simply sweeping the memory addresses in decreasing order does not work. So I had to add a pair of dec de and inc de at the cost of 2 bytes (plus 4 bytes to push the 2 bytes into the stack).

The second loop prints the main code by popping data from the stack.

Possible improvement ideas

Since the code is longer than $38 or 56 bytes, we can't use rst $38 in place of call $8000. Having call $8000 6 times in total, it's a great opportunity for golf. I considered placing call $8000; ret at address $38, but then I have to reduce the main code into 26 bytes or lower.

I also thought of moving the code to the front by adding some jr, so that I can embed the call $8000; ret in the code part. But then I can't use the efficient "pop and print" loop. It prints the data in reverse order of pushing, so it can't be used to print the push part; the "print" overwrites the stack with the return address, so it can't be used to print the first part either.

Finally, there is room for alternative encoding since some bytes frequently appear in the code. But Z80 itself is severely limited in arithmetic...

\$\endgroup\$
4
\$\begingroup\$

MathGolf, 9 bytes

ÿ_'ÿ¬_'ÿ¬

Try it online!

Explanation:

ÿ_'ÿ¬_'ÿ¬
ÿ          Start string of length 4
 _'ÿ¬      Push "_'ÿ¬"
     _     Duplicate it
      'ÿ   Push the character "ÿ"
        ¬  Rotate stack so the "ÿ" is at the bottom
           Implicitly output "ÿ", "_'ÿ¬", "_'ÿ¬" join together
\$\endgroup\$
  • \$\begingroup\$ ÿ'ÿ¬_'ÿ¬_ is another 9-byter. \$\endgroup\$ – maxb Jan 7 at 11:56
4
\$\begingroup\$

Perl 6, 31 27 bytes

<"<$_>~~.EVAL".say>~~.EVAL

Try it online!

No messing about with alternative q quotes or .perl, just <> and a good ol' EVAL quine.

Explanation:

<                 >         # Create a list of 
 "<$_>~~.EVAL".say          # The string '"<$_>~~.EVAL".say'
                   ~~       # Smartmatch the list by setting $_ to it
                     .EVAL  # Evaluate the string as code
 "<$_>~~.EVAL"              # Interpolate the $_ list into the string
              .say          # And print it with a newline
\$\endgroup\$
4
\$\begingroup\$

APL (Dyalog Unicode), 18 bytesSBCS

@ngn's updated version of the classic APL quine, using a modern operator to save four bytes.

1⌽,⍨9⍴'''1⌽,⍨9⍴'''

Try APL!

'''1⌽,⍨9⍴''' the characters '1⌽,⍨9⍴'

9⍴ cyclically reshape to shape 9; '1⌽,⍨9⍴''

,⍨ concatenation selfie; '1⌽,⍨9⍴'''1⌽,⍨9⍴''

1⌽ cyclically rotate one character to the left; 1⌽,⍨9⍴'''1⌽,⍨9⍴'''

\$\endgroup\$
4
\$\begingroup\$

Ruby, 27 bytes

eval s="$><<'eval s=';p s"

Try it online!

$><<'...' is equivalent to print'...' (outputs the string without a newline).

Note the newline at the end of the program.

\$\endgroup\$
  • \$\begingroup\$ Welcome to the site! Nice first answer :) \$\endgroup\$ – DJMcMayhem Jun 12 '17 at 17:07
  • 1
    \$\begingroup\$ doesn't p print a newline? \$\endgroup\$ – Shelvacu Aug 11 at 23:20
  • \$\begingroup\$ @Shelvacu You're right; it should be 27 bytes. Interestingly, I went back and looked around, and I couldn't find any Ruby quines that included a newline in their source to match the output. Most seem to add an extra newline in their output like this one did. I also have a vague memory of coming across a 25-byte Ruby quine somewhere, I think in a demonstration of a new-at-the-time feature, but I haven't been able to find it again. \$\endgroup\$ – Nnnes Aug 12 at 23:43
3
\$\begingroup\$

(ucb)logo - 28 chars

to q
po "q
pr "q
bye
end

q
\$\endgroup\$
3
\$\begingroup\$

Mathematica 17 19

ToString[#0][] & []
\$\endgroup\$
  • \$\begingroup\$ Why Community Wiki? \$\endgroup\$ – MD XF Jun 12 '17 at 23:47
3
\$\begingroup\$

Pyth, 11 bytes

jN*2]"jN*2]

Surprised this hadn't been posted yet :P

\$\endgroup\$
3
\$\begingroup\$

ShapeScript, 16 bytes

'"%r"@%"0?!"'0?!

This answer is non-competing, since ShapeScript is a few years younger than this challenge.

Try it online!

Verification

$ shapescript quine.shape | diff -sq - quine.shape
Files - and quine.shape are identical

How it works

'       Push a string that, when evaluated, does the following.
  "%r"  Push this formatting string. %r gets replaced by a string
        representation of the corresponding argument.
  @     Swap the string that is being evaluated on top of the stack.
  %     Apply formatting to the string on top of the stack.
  "0?!" Push that string.
'
0?!     Push a copy of the previous string and evaluate it.

ShapeScript, 32 bytes

'"'"'"'1?3?+3*2?+@+@+@#"0?!"'0?!

This version does not use string formatting. It's not particularly short, but I find it rather interesting.

Try it online!

How it works

'"'     Push a double quote singleton string.
"'"     Push a single quote singleton string.
'       Push a string that, when evaluated, does the following:
  1?3?    Copy the second and fourth topmost stack items.
          This pushes a copy of the single, then the double quote.
  +3*     Concatenate both and repeat the result three times.
  2?+     Copy the third topmost stack item and append it to the string.
          We now have a string of the first seven characters of the source.
  @+      Swap with the string on the stack (the string that is being
          evaluated) and concatenate.
  @+      Swap with the original single quote and concatenate.
  @#      Swap with the original double quote and discard it.
  "0?!"   Push that string.
'
0?!     Push a copy of the above string and evaluate it.
\$\endgroup\$
3
\$\begingroup\$

SWI-Prolog, 22 bytes

a :-
        listing(a).
 

A surprisingly short and elegant solution.

The 8 spaces and the new line (the space in the last line is just to display the empty line, there is actually no space) are both required in SWI-Prolog because that is the formatting that listing displays in the interpreter.

\$\endgroup\$
3
\$\begingroup\$

Brachylog, 3 bytes

@Qw

This expects no input or output, i.e. brachylog_main(_,_)..

@Q is the string "@Qw", and w is the write predicate.

A 34 bytes quine without a specific built-in for quines

"~c~s~cS:[34:S:34]rw"S:[34:S:34]rw

This is a basic quine strategy applied to this language:

"~c~s~cS:[34:S:34]rw"              § Create a string containing the source code
                                   § ~c~s~c gets replaced by the arguments of predicate w
                                   § in their respective order in the list
                                   § ~c prints the arg as a char code, ~s as a string
                     S             § Call this string S
                      :[34:S:34]rw § Write the format S to the output with args " (34),
                                   § S and " replacing ~c, ~s and ~c respectively
\$\endgroup\$
3
\$\begingroup\$

Squeak Smalltalk - 91!

I just translated my Factor answer:

[:b|b value:b]value:[:b|Transcript show: '[:b|b value:b]value:[:b|' , b sourceString , ']']

Just DoIt! in a Workspace, prints itself to the Transcript.

Blocks don't have a reference to self, so i used another block as a combinator.

I'm sure there MUST be a shorter Smalltalk quine! After all it's Small-talk :P

No cheating -- that means that you can't just read the source file and print it.

At first I thought BlockClosure>>sourceString could be cheating as stated in the question, but looking at the Squeak implementation, doesn't seem to be reading the sources file1, but decompiling the block.

1: Smalltalk's image usually saves compiled code, and links to an external file with the original source.

\$\endgroup\$
  • \$\begingroup\$ It's cheating if b is your whole program. However, if b is a function or string literal, it's fine. \$\endgroup\$ – wizzwizz4 Feb 14 '16 at 9:05
  • \$\begingroup\$ @wizzwizz4 Thanks for the clarification! \$\endgroup\$ – fede s. Feb 14 '16 at 21:56
  • \$\begingroup\$ Yeah sourceString looks like "read[ing] the source file and print[ing] it". \$\endgroup\$ – Martin Ender Feb 14 '16 at 22:34
  • 1
    \$\begingroup\$ The second largest program I've seen. 91! = 1.352002e+140 :P \$\endgroup\$ – user48538 May 16 '16 at 20:29
  • 1
    \$\begingroup\$ @fedes. probably needs more jQuery \$\endgroup\$ – cat May 17 '16 at 23:23
3
\$\begingroup\$

Go, 115 bytes

package main;import."fmt";func main(){s:="package main;import.\"fmt\";func main(){s:=%q;Printf(s,s);}";Printf(s,s)}

Blowing the previous Go record out of the water!

\$\endgroup\$
  • \$\begingroup\$ Nice job, there! \$\endgroup\$ – Conor O'Brien Mar 23 '16 at 17:53
3
\$\begingroup\$

Python, 104 bytes

Uses eval and repr

a = "print 'a','=', repr(eval('a'))\nprint eval('a'),\n"
print 'a','=', repr(eval('a'))
print eval('a'),
\$\endgroup\$
  • 3
    \$\begingroup\$ Since this is code-golf, you might want to include a byte count. \$\endgroup\$ – nyuszika7h Apr 28 '14 at 12:33
  • 1
    \$\begingroup\$ repr(x)==`x` \$\endgroup\$ – CalculatorFeline Mar 10 '16 at 23:58
3
\$\begingroup\$

Ouroboros, 30 bytes

;T...!59*\1=33*++o.9=\1=2*+(1"

The T should be replaced with a literal tab character.

About Ouroboros

Each line of an Ouroboros program represents a snake eating its own tail, with the beginning of the line being the head and the end being the tail. The only control flow operations are commands to eat or regurgitate characters of the tail. When the instruction pointer reaches the last part of the line that hasn't been eaten, it loops back to the beginning. If the instruction pointer is swallowed, execution halts.

While Ouroboros has some similarities to 2D languages such as ><>, its limited control flow options presented a challenge for quine construction. The only way to skip an instruction is to put it near the end and swallow it--which means instructions near the beginning basically can't be skipped. It took some experimenting before I found a quine structure that worked.

Explanation

The core idea is similar to a ><> or Befunge quine: with a wrapping IP, a single " mark can be used to stringify the code on one pass and execute it on another. Ouroboros automatically pushes strings to the stack in reverse order, which simplifies things. However, we have to put the quotation mark at the end so we can swallow it to avoid pushing the string multiple times. That means that the code must be executed first, then the string pushed, and then the code executed again until the output is complete.

On every pass, the code does two main things: output a character and swallow 0 or more characters of code.

...!59*\1=33*++o

On the first pass, the stack is empty and treated as zero. Logically negating and multiplying by 59 gives the character code for ;, the first character of the quine. On the final pass, the 1 that was pushed right before the string (at the very end of the code) is encountered, to which we add 33 to turn it into 34, the closing ". On other passes, the character code is output unchanged. In pseudocode: output (!top)*59 + (top==1)*33 + top

.9=\1=2*+(

There are two passes on which code needs to be swallowed. On the first pass after we push the string (when we print the tab) the quotation mark has to go; and on the last pass (after we've processed the whole string and the 1 is left on the stack) two more characters are eaten to swallow the instruction pointer and end the program. On every other pass, don't eat anything. In pseudocode: swallow (top==9)+(top==1)*2

One problem remains: since we output the first character of code on the initial pass, we have to drop it (;) immediately after pushing the string so it won't be output a second time. But we don't want to drop anything on subsequent passes. Fortunately, at the end of each iteration we push another 1 to the stack, which is immediately dropped at the beginning of the next pass.

Try it out

// Define Stack class
function Stack() {
  this.stack = [];
  this.length = 0;
}
Stack.prototype.push = function(item) {
  this.stack.push(item);
  this.length++;
}
Stack.prototype.pop = function() {
  var result = 0;
  if (this.length > 0) {
    result = this.stack.pop();
    this.length--;
  }
  return result;
}
Stack.prototype.top = function() {
  var result = 0;
  if (this.length > 0) {
    result = this.stack[this.length - 1];
  }
  return result;
}
Stack.prototype.toString = function() {
  return "" + this.stack;
}

// Define Snake class
function Snake(code) {
  this.code = code;
  this.length = this.code.length;
  this.ip = 0;
  this.ownStack = new Stack();
  this.currStack = this.ownStack;
  this.alive = true;
  this.wait = 0;
  this.partialString = this.partialNumber = null;
}
Snake.prototype.step = function() {
  if (!this.alive) {
    return null;
  }
  if (this.wait > 0) {
    this.wait--;
    return null;
  }
  var instruction = this.code.charAt(this.ip);
  var output = null;
  console.log("Executing instruction " + instruction);
  if (this.partialString !== null) {
    // We're in the middle of a double-quoted string
    if (instruction == '"') {
      // Close the string and push its character codes in reverse order
      for (var i = this.partialString.length - 1; i >= 0; i--) {
        this.currStack.push(this.partialString.charCodeAt(i));
      }
      this.partialString = null;
    } else {
      this.partialString += instruction;
    }
  } else if (instruction == '"') {
    this.partialString = "";
  } else if ("0" <= instruction && instruction <= "9") {
    if (this.partialNumber !== null) {
      this.partialNumber = this.partialNumber + instruction;  // NB: concatenation!
    } else {
      this.partialNumber = instruction;
    }
    next = this.code.charAt((this.ip + 1) % this.length);
    if (next < "0" || "9" < next) {
      // Next instruction is non-numeric, so end number and push it
      this.currStack.push(+this.partialNumber);
      this.partialNumber = null;
    }
  } else if ("a" <= instruction && instruction <= "f") {
    // a-f push numbers 10 through 15
    var value = instruction.charCodeAt(0) - 87;
    this.currStack.push(value);
  } else if (instruction == "$") {
    // Toggle the current stack
    if (this.currStack === this.ownStack) {
      this.currStack = this.program.sharedStack;
    } else {
      this.currStack = this.ownStack;
    }
  } else if (instruction == "s") {
    this.currStack = this.ownStack;
  } else if (instruction == "S") {
    this.currStack = this.program.sharedStack;
  } else if (instruction == "l") {
    this.currStack.push(this.ownStack.length);
  } else if (instruction == "L") {
    this.currStack.push(this.program.sharedStack.length);
  } else if (instruction == ".") {
    var item = this.currStack.pop();
    this.currStack.push(item);
    this.currStack.push(item);
  } else if (instruction == "m") {
    var item = this.ownStack.pop();
    this.program.sharedStack.push(item);
  } else if (instruction == "M") {
    var item = this.program.sharedStack.pop();
    this.ownStack.push(item);
  } else if (instruction == "y") {
    var item = this.ownStack.top();
    this.program.sharedStack.push(item);
  } else if (instruction == "Y") {
    var item = this.program.sharedStack.top();
    this.ownStack.push(item);
  } else if (instruction == "\\") {
    var top = this.currStack.pop();
    var next = this.currStack.pop()
    this.currStack.push(top);
    this.currStack.push(next);
  } else if (instruction == "@") {
    var c = this.currStack.pop();
    var b = this.currStack.pop();
    var a = this.currStack.pop();
    this.currStack.push(c);
    this.currStack.push(a);
    this.currStack.push(b);
  } else if (instruction == ";") {
    this.currStack.pop();
  } else if (instruction == "+") {
    var b = this.currStack.pop();
    var a = this.currStack.pop();
    this.currStack.push(a + b);
  } else if (instruction == "-") {
    var b = this.currStack.pop();
    var a = this.currStack.pop();
    this.currStack.push(a - b);
  } else if (instruction == "*") {
    var b = this.currStack.pop();
    var a = this.currStack.pop();
    this.currStack.push(a * b);
  } else if (instruction == "/") {
    var b = this.currStack.pop();
    var a = this.currStack.pop();
    this.currStack.push(a / b);
  } else if (instruction == "%") {
    var b = this.currStack.pop();
    var a = this.currStack.pop();
    this.currStack.push(a % b);
  } else if (instruction == "_") {
    this.currStack.push(-this.currStack.pop());
  } else if (instruction == "I") {
    var value = this.currStack.pop();
    if (value < 0) {
      this.currStack.push(Math.ceil(value));
    } else {
      this.currStack.push(Math.floor(value));
    }
  } else if (instruction == ">") {
    var b = this.currStack.pop();
    var a = this.currStack.pop();
    this.currStack.push(+(a > b));
  } else if (instruction == "<") {
    var b = this.currStack.pop();
    var a = this.currStack.pop();
    this.currStack.push(+(a < b));
  } else if (instruction == "=") {
    var b = this.currStack.pop();
    var a = this.currStack.pop();
    this.currStack.push(+(a == b));
  } else if (instruction == "!") {
    this.currStack.push(+ !this.currStack.pop());
  } else if (instruction == "?") {
    this.currStack.push(Math.random());
  } else if (instruction == "n") {
    output = "" + this.currStack.pop();
  } else if (instruction == "o") {
    output = String.fromCharCode(this.currStack.pop());
  } else if (instruction == "r") {
    var input = this.program.io.getNumber();
    this.currStack.push(input);
  } else if (instruction == "i") {
    var input = this.program.io.getChar();
    this.currStack.push(input);
  } else if (instruction == "(") {
    this.length -= Math.floor(this.currStack.pop());
    this.length = Math.max(this.length, 0);
  } else if (instruction == ")") {
    this.length += Math.floor(this.currStack.pop());
    this.length = Math.min(this.length, this.code.length);
  } else if (instruction == "w") {
    this.wait = this.currStack.pop();
  }
  // Any unrecognized character is a no-op
  if (this.ip >= this.length) {
    // We've swallowed the IP, so this snake dies
    this.alive = false;
    this.program.snakesLiving--;
  } else {
    // Increment IP and loop if appropriate
    this.ip = (this.ip + 1) % this.length;
  }
  return output;
}
Snake.prototype.getHighlightedCode = function() {
  var result = "";
  for (var i = 0; i < this.code.length; i++) {
    if (i == this.length) {
      result += '<span class="swallowedCode">';
    }
    if (i == this.ip) {
      if (this.wait > 0) {
        result += '<span class="nextActiveToken">';
      } else {
        result += '<span class="activeToken">';
      }
      result += escapeEntities(this.code.charAt(i)) + '</span>';
    } else {
      result += escapeEntities(this.code.charAt(i));
    }
  }
  if (this.length < this.code.length) {
    result += '</span>';
  }
  return result;
}

// Define Program class
function Program(source, speed, io) {
  this.sharedStack = new Stack();
  this.snakes = source.split(/\r?\n/).map(function(snakeCode) {
    var snake = new Snake(snakeCode);
    snake.program = this;
    snake.sharedStack = this.sharedStack;
    return snake;
  }.bind(this));
  this.snakesLiving = this.snakes.length;
  this.io = io;
  this.speed = speed || 10;
  this.halting = false;
}
Program.prototype.run = function() {
  this.step();
  if (this.snakesLiving) {
    this.timeout = window.setTimeout(this.run.bind(this), 1000 / this.speed);
  }
}
Program.prototype.step = function() {
   for (var s = 0; s < this.snakes.length; s++) {
    var output = this.snakes[s].step();
    if (output) {
      this.io.print(output);
    }
  }
  this.io.displaySource(this.snakes.map(function (snake) {
      return snake.getHighlightedCode();
    }).join("<br>"));
 }
Program.prototype.halt = function() {
  window.clearTimeout(this.timeout);
}

var ioFunctions = {
  print: function (item) {
    var stdout = document.getElementById('stdout');
    stdout.value += "" + item;
  },
  getChar: function () {
    if (inputData) {
      var inputChar = inputData[0];
      inputData = inputData.slice(1);
      result = inputChar.charCodeAt(0);
    } else {
      result = -1;
    }
    var stdinDisplay = document.getElementById('stdin-display');
    stdinDisplay.innerHTML = escapeEntities(inputData);
    return result;
  },
  getNumber: function () {
    while (inputData && (inputData[0] < "0" || "9" < inputData[0])) {
      inputData = inputData.slice(1);
    }
    if (inputData) {
      var inputNumber = inputData.match(/\d+/)[0];
      inputData = inputData.slice(inputNumber.length);
      result = +inputNumber;
    } else {
      result = -1;
    }
    var stdinDisplay = document.getElementById('stdin-display');
    stdinDisplay.innerHTML = escapeEntities(inputData);
    return result;
  },
  displaySource: function (formattedCode) {
    var sourceDisplay = document.getElementById('source-display');
    sourceDisplay.innerHTML = formattedCode;
  }
};
var program = null;
var inputData = null;
function showEditor() {
  var source = document.getElementById('source'),
    sourceDisplayWrapper = document.getElementById('source-display-wrapper'),
    stdin = document.getElementById('stdin'),
    stdinDisplayWrapper = document.getElementById('stdin-display-wrapper');
  
  source.style.display = "block";
  stdin.style.display = "block";
  sourceDisplayWrapper.style.display = "none";
  stdinDisplayWrapper.style.display = "none";
  
  source.focus();
}
function hideEditor() {
  var source = document.getElementById('source'),
    sourceDisplay = document.getElementById('source-display'),
    sourceDisplayWrapper = document.getElementById('source-display-wrapper'),
    stdin = document.getElementById('stdin'),
    stdinDisplay = document.getElementById('stdin-display'),
    stdinDisplayWrapper = document.getElementById('stdin-display-wrapper');
  
  source.style.display = "none";
  stdin.style.display = "none";
  sourceDisplayWrapper.style.display = "block";
  stdinDisplayWrapper.style.display = "block";
  
  var sourceHeight = getComputedStyle(source).height,
    stdinHeight = getComputedStyle(stdin).height;
  sourceDisplayWrapper.style.minHeight = sourceHeight;
  sourceDisplayWrapper.style.maxHeight = sourceHeight;
  stdinDisplayWrapper.style.minHeight = stdinHeight;
  stdinDisplayWrapper.style.maxHeight = stdinHeight;
  sourceDisplay.textContent = source.value;
  stdinDisplay.textContent = stdin.value;
}
function escapeEntities(input) {
  return input.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}
function resetProgram() {
  var stdout = document.getElementById('stdout');
  stdout.value = null;
  if (program !== null) {
    program.halt();
  }
  program = null;
  inputData = null;
  showEditor();
}
function initProgram() {
  var source = document.getElementById('source'),
    stepsPerSecond = document.getElementById('steps-per-second'),
    stdin = document.getElementById('stdin');
  program = new Program(source.value, +stepsPerSecond.innerHTML, ioFunctions);
  hideEditor();
  inputData = stdin.value;
}
function runBtnClick() {
  if (program === null || program.snakesLiving == 0) {
    resetProgram();
    initProgram();
  } else {
    program.halt();
    var stepsPerSecond = document.getElementById('steps-per-second');
    program.speed = +stepsPerSecond.innerHTML;
  }
  program.run();
}
function stepBtnClick() {
  if (program === null) {
    initProgram();
  } else {
    program.halt();
  }
  program.step();
}
function sourceDisplayClick() {
  resetProgram();
}
.container {
    width: 100%;
}
.so-box {
    font-family:'Helvetica Neue', Arial, sans-serif;
    font-weight: bold;
    color: #fff;
    text-align: center;
    padding: .3em .7em;
    font-size: 1em;
    line-height: 1.1;
    border: 1px solid #c47b07;
    -webkit-box-shadow: 0 2px 2px rgba(0, 0, 0, 0.3), 0 2px 0 rgba(255, 255, 255, 0.15) inset;
    text-shadow: 0 0 2px rgba(0, 0, 0, 0.5);
    background: #f88912;
    box-shadow: 0 2px 2px rgba(0, 0, 0, 0.3), 0 2px 0 rgba(255, 255, 255, 0.15) inset;
}
.control {
    display: inline-block;
    border-radius: 6px;
    float: left;
    margin-right: 25px;
    cursor: pointer;
}
.option {
    padding: 10px 20px;
    margin-right: 25px;
    float: left;
}
h1 {
    text-align: center;
    font-family: Georgia, 'Times New Roman', serif;
}
a {
    text-decoration: none;
}
input, textarea {
    box-sizing: border-box;
}
textarea {
    display: block;
    white-space: pre;
    overflow: auto;
    height: 50px;
    width: 100%;
    max-width: 100%;
    min-height: 25px;
}
span[contenteditable] {
    padding: 2px 6px;
    background: #cc7801;
    color: #fff;
}
#stdout-container, #stdin-container {
    height: auto;
    padding: 6px 0;
}
#reset {
    float: right;
}
#source-display-wrapper , #stdin-display-wrapper{
    display: none;
    width: 100%;
    height: 100%;
    overflow: auto;
    border: 1px solid black;
    box-sizing: border-box;
}
#source-display , #stdin-display{
    font-family: monospace;
    white-space: pre;
    padding: 2px;
}
.activeToken {
    background: #f93;
}
.nextActiveToken {
    background: #bbb;
}
.swallowedCode{
    color: #999;
}
.clearfix:after {
    content:".";
    display: block;
    height: 0;
    clear: both;
    visibility: hidden;
}
.clearfix {
    display: inline-block;
}
* html .clearfix {
    height: 1%;
}
.clearfix {
    display: block;
}
<!--
Designed and written 2015 by D. Loscutoff
Much of the HTML and CSS was taken from this Befunge interpreter by Ingo Bürk: http://codegolf.stackexchange.com/a/40331/16766
-->
<div class="container">
<textarea id="source" placeholder="Enter your program here" wrap="off">;	...!59*\1=33*++o.9=\1=2*+(1"</textarea>
<div id="source-display-wrapper" onclick="sourceDisplayClick()"><div id="source-display"></div></div></div><div id="stdin-container" class="container">
<textarea id="stdin" placeholder="Input" wrap="off"></textarea>
<div id="stdin-display-wrapper" onclick="stdinDisplayClick()"><div id="stdin-display"></div></div></div><div id="controls-container" class="container clearfix"><input type="button" id="run" class="control so-box" value="Run" onclick="runBtnClick()" /><input type="button" id="pause" class="control so-box" value="Pause" onclick="program.halt()" /><input type="button" id="step" class="control so-box" value="Step" onclick="stepBtnClick()" /><input type="button" id="reset" class="control so-box" value="Reset" onclick="resetProgram()" /></div><div id="stdout-container" class="container"><textarea id="stdout" placeholder="Output" wrap="off" readonly></textarea></div><div id="options-container" class="container"><div class="option so-box">Steps per Second:
<span id="steps-per-second" contenteditable>20</span></div></div>

\$\endgroup\$
3
\$\begingroup\$

R, 73 bytes (incl. tabs and newlines)

(f=function()
{
    cat("(f=function()\n")
    print(body(f))
    cat(")()")
}
)()

Shorter, less interesting quines are possible: function()1 is 11 bytes. + (1 byte) is an arguable quine, since the command prompt for an unfinished line is a plus sign by default, and + on its own counts as an unfinished line.

\$\endgroup\$
  • \$\begingroup\$ It is necessary to format exactly this way (can't remove tabs or replace newline with ";"), otherwise the output will not exactly match the input. \$\endgroup\$ – JDL Aug 25 '16 at 14:17
  • \$\begingroup\$ A more trivial example is function()1 (11 bytes) but that's kinda boring... \$\endgroup\$ – JDL Aug 26 '16 at 14:06
  • 2
    \$\begingroup\$ Your 14 bytes solution is not easy to find. And I don't find it boring at all! Suggestion: keep the 73 solution but list this solution as 14 bytes one so it found more easily using the leaderboard. \$\endgroup\$ – JayCe May 16 '18 at 17:56
  • \$\begingroup\$ I may be misreading some details of how programs are defined in R, but I think list() is a shorter trivial solution? I can't do command-line verification, but it certainly plays interactively and on TIO (though you might argue a newline is needed for the latter) Try it online! \$\endgroup\$ – CriminallyVulgar Jan 31 at 15:37
  • \$\begingroup\$ yes, list() (and numeric(0) and friends) are all quines in R. \$\endgroup\$ – JDL Feb 1 at 8:57
3
\$\begingroup\$

J 4 bytes

I know this competition is probably dead but I wanted to put my answer in.

Just found this by accident

1 b.

J 1 bytes

0
\$\endgroup\$
  • 1
    \$\begingroup\$ Nice... I think you found the shortest possible quine once again! \$\endgroup\$ – Erik the Outgolfer Sep 14 '16 at 13:32
  • 3
    \$\begingroup\$ These basically rely on the repl state of J, and are rather trivial. But, if it's happening like this, 1& is shorter than 1 b.. \$\endgroup\$ – Conor O'Brien Oct 14 '16 at 22:58
  • \$\begingroup\$ 28 Bytes for a full program: (echo@,quote)'(echo@,quote)' \$\endgroup\$ – Bolce Bussiere Apr 2 '18 at 2:29
3
\$\begingroup\$

C#, 188 157 149 bytes

class A{static void Main(){var a="class A{{static void Main(){{var a={0}{1}{0};System.Console.Write(a,'{0}',a);}}}}";System.Con‌​sole.Write(a,'"',a);‌​}}

Basic quine, just contains a self-containing string.

\$\endgroup\$
  • \$\begingroup\$ More shorter version (149 bytes): class A{static void Main(){var a="class A{{static void Main(){{var a={0}{1}{0};System.Console.Write(a,'{0}',a);}}}}";System.Console.Write(a,'"',a);}} \$\endgroup\$ – Ivan Kochurkin Sep 15 '16 at 11:19
3
\$\begingroup\$

BaCon, 55 bytes

Without using the SOURCE$ variable, the smallest Quine is 55 bytes:

s$="s$=%c%s%c:?34,s$,34 FORMAT s$":?34,s$,34 FORMAT s$
\$\endgroup\$
  • 2
    \$\begingroup\$ please make the main part of the post the 55 byte noncheating quine \$\endgroup\$ – Destructible Lemon Oct 14 '16 at 21:05
  • \$\begingroup\$ Done. I wonder why using 'SOURCE$' is cheating, looking at the other contributions? \$\endgroup\$ – Peter Oct 15 '16 at 20:05
  • 1
    \$\begingroup\$ The other answers are also cheating. This challenge is over five years old; most answers were posted before we had clearly defined rules. Since last month, improper quines are officially forbidden in all challenges, even if the spec doesn't explicitly forbid them. \$\endgroup\$ – Dennis Oct 15 '16 at 20:13
  • \$\begingroup\$ Thanks for pointing me to this page, I was unaware of it. \$\endgroup\$ – Peter Oct 16 '16 at 20:29
  • \$\begingroup\$ The smallest BaCon quine is 55 bytes? Guess again. \$\endgroup\$ – MD XF May 26 '17 at 15:40
3
\$\begingroup\$

Rust, 173 158 152 144 137 102 bytes

Tuples plus Rust's debug printing mechanism ( {:?} in a format string ) let me cut it down 30+ characters!

fn main(){let t=("fn main(){let t=", ";print!(\"{}{:?}{}\",t.0,t,t.1)}");print!("{}{:?}{}",t.0,t,t.1)}

Pretty-printed. It's so small there's little left to explain!

fn main() {
    // The space after the comma is necessary, because that's how
    // debug-print formats tuples
    let t=("fn main(){let t=", ";print!(\"{}{:?}{}\",t.0,t,t.1)}");
    print!("{}{:?}{}",t.0,t,t.1)
}
\$\endgroup\$
3
\$\begingroup\$

BotEngine, 4x1=4 bytes

TRUE

The T instruction deletes the active bot and prints TRUE.

\$\endgroup\$
3
\$\begingroup\$

Haystack, 7 bytes

Yay, my first quine!

"34c,o|

Try it online!

Explanation

This is a standard 2D quine.

"           starts to push a string
34c,o|      part of the string
"           it wraps around and go to the beginning of this line thus pushing the string
34          push this number
c           output as character (ie outputs ")
,           discard this value
o           output the top of stack (ie 34c,o|)
|           end program
\$\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.