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

365 Answers 365

1
5 6
7
8 9
13
3
\$\begingroup\$

Awk, 64 bytes

BEGIN{c="BEGIN{c=%c%s%c;printf c,34,c,34}";printf c,34,c,34}
| improve this answer | |
\$\endgroup\$
3
\$\begingroup\$

><>, 8 bytes

#o<}-1:"

Try It Online

Copied the trick of copying and decrementing the # to get " from the other ><> answer, but uses both sides of the # to avoid needing to reverse the stack.

Edit: A much cleaner solution of the same length:

'rd3*>o<

Try it online!

Everyone forgets that a ' acts exactly the same as a ", but has usable divisors. Another 8 byte solution, but considered cheaty by some, 'r00g>o<

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ This is the same approach I used in the comments of the Original ><> answer: Funnily enough my comment and your post were 1 day off being exactly a year apart. \$\endgroup\$ – Teal pelican Jan 9 '18 at 16:11
  • 1
    \$\begingroup\$ @Tealpelican. Wait, why didn’t we just use a single quote? \$\endgroup\$ – Jo King Jan 19 '18 at 4:40
  • \$\begingroup\$ I always forget ><> can use ' or " but ' is so much more useful with having some usable divisors. \$\endgroup\$ – Teal pelican Jan 19 '18 at 9:39
3
\$\begingroup\$

DipDup, 6 bytes

[_:]_:

Try it online!

Explanation

[_:]        push this list
    _       duplicate
     :      cons
| improve this answer | |
\$\endgroup\$
3
\$\begingroup\$

Gol><>, 6 5 bytes

sP#H"

Try it online!

Credit to Jo King.

How it works

sP#H"

s      +16
 P     +1
  #    Reverse direction
 P     +1
s      +16
    "  Start string literal
sP#H"  Push H, #, P, s and end string literal
   H   Print everything on the stack from the top, and halt
       The printed chars are s, P, #, H, 34 (")

Previous solution, 6 bytes

"r2ssH

Try it online!

How it works

"r2ssH  Push the string "r2ssH" to stack, "r" being at the bottom
"       Close the literal
 r      Reverse the stack
  2ss   Push 34 (")
     H  Print all content of the stack from top to bottom as chars, and halt

There were a couple of alternatives to consider:

  • S" prints the string right away (instead of pushing to stack), but then it gets harder to handle ".
  • `" is an alternative way to push 34 to the stack, but the string literal also treats `" as escaped " which is not desirable.
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ An interesting 8 byter using S" \$\endgroup\$ – Jo King Nov 28 '18 at 0:34
3
\$\begingroup\$

MATL, 12 bytes

'&DtU'
&DtU

(the code has a trailing newline).

Try it online!

Explanation

'&DtU'    % Push this string
&D        % String representation (adds quote marks)
t         % Duplicate
U         % Evaluate (removes quote marks)
          % Implicitly display each string followed by a newline
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ I take it that it would not be shorter to do &D after t, avoiding U? \$\endgroup\$ – ETHproductions Oct 23 '16 at 2:56
  • \$\begingroup\$ @ETHproductions Not sure if I understand your suggestion correctly. I think &D needs to be after t because the second part of the displayed output needs to be without quotes \$\endgroup\$ – Luis Mendo Oct 23 '16 at 3:00
  • 1
    \$\begingroup\$ I mean that unevaling the string &D and then re-evaling U seems a little redundant. It's probably not shorter any other way, though, as you would likely need to use stack manipulation. \$\endgroup\$ – ETHproductions Oct 23 '16 at 3:03
  • \$\begingroup\$ @ETHproductions Oh, now I see what you mean: this, right? (w is swap). As you say, it's not shorter unfortunately \$\endgroup\$ – Luis Mendo Oct 23 '16 at 3:08
  • \$\begingroup\$ Yeah, that's what I meant, and that's what I figured \$\endgroup\$ – ETHproductions Oct 23 '16 at 3:09
3
\$\begingroup\$

Noether, 30 bytes

"~a34BPaP34BPaP"~a34BPaP34BPaP

Try it online!

Basically, this works by pushing the string and storing it in the variable a, printing quotation marks (34B where B pushes the character with ASCII code 34) then printing a twice.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ @OMᗺ That's only the Python/tio.run interpreter (which has a few bugs) . On the JS interpreter, there is no newline. \$\endgroup\$ – Beta Decay Aug 11 '18 at 13:59
  • \$\begingroup\$ Alright, that's the one on TIO so I tried with that sorry! Nvm, in that case. \$\endgroup\$ – ბიმო Aug 11 '18 at 14:01
3
\$\begingroup\$

J, 27 bytes

echo(,quote)'echo(,quote)'

Try it online!

It's surprising that there's no proper J quine submission yet.

How it works

echo(,quote)'echo(,quote)'
            'echo(,quote)'  The string `s`
      quote                 Wrap `s` with single quotes
     ,                      Concat s to the above; `(f g)x` is equal to `x f g x`
echo                        Explicitly print the result

echo is needed because the result of a non-REPL line is not printed.

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

Flobnar, 94 bytes

	9	f;	/*+{ ;{?06	0/9^[]={o)	*4_;=	9);];36   
:
g<
0+,|!<|@17
10:_\^>|p*
+5`<>
:*<  ^ <47!!!

Try it online!

There's some debate over whether the get instruction counts as reading the source code, but in this case, I'm not using it to read the executed code, but a data array on the first line (except for specifically reusing just the 9 character).

This reads and prints the data section, then reads and prints each character incremented by one to represent the code section.

Explanation:

.
..
.....<|@..   Start at the @ going left
..........   We use the | to evaluate the code beyond it and come back here
.....
.............

:
g<
0+,|!<....   Print the character on the first line at position n plus 0
.0........   Then go down from the |
.....
.............

.9
.
..
...|!.....
..:_......   If n > 5*9 then go left at the _ and return !n
.5`<.
.*<..........

.
..
...|!<....   Else go right and increment n
1.._\^....   And loop again
+...>
:............

.
..           Once we've ended the loop we come back to the original | going down
.....<|.17   And we put a 1 at the (1,4) position and repeat the main code again
.1....>|p*   This time adding 1 to each character
.....
.....^ <47...
| improve this answer | |
\$\endgroup\$
3
\$\begingroup\$

Runic Enchantments, 7 6 bytes

"'<~@>

Try it online!

Huh, a multiple pointer quine actually works pretty well.

Explanation:

"'<~@>
  <  >   Start pointers going left and right
"'<      Left pointer pushes " to their stack
    @    And terminate the IP, printing the stack (")
     >   Right pointer wraps around
"        Start string literal
 '<~@>   Push as string
"        End string literal
 '<~     Push the < character, but pop it
    @    Terminate the IP, printing the stack ('<~@>)
         End the program as there are no IPs left

Edit: I realised you can replicate this with only one pointer

'<~@|"

Try it online!

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Ha, didn't even see prior to posting this and you already beat me. Very clever use of the multiple IP feature. \$\endgroup\$ – Draco18s no longer trusts SE Oct 1 '18 at 18:22
3
\$\begingroup\$

Symbolic Python, 30 bytes

_="_='_='+`_`+';__(_)'";__(_)

Try it online!

Yet another eval quine. The lack of being able to do %r in Symbolic Python is made up for Python 2's backticks, which are an alias for the repr function.

Explanation:

_="                   ";       # Assign the string to the _ variable
                        __(_)  # Eval the string
   _=                          # Assign to the _ variable
     '_='                      # The initial _=
         +`_`                  # The Python representation of the string
             +';__(_)'         # And the final evaling part
                               # Implicitly output the contents of _

An alternative that doesn't use the rather long eval function comes to 31 bytes, but I actually like it more.

_=';_="_="+`_`+_';_="_="+`_`+_

Try it online!

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

Gol><>, 8 7 6 bytes

"r2ssH

Hopefully this is not a previously used quine, I was messing around for another challenge having to do with quines, and I ended up creating this!

2nd program (the most recent), 7 bytes

":P}rH!

Courtesy of JoKing, who knocked an entire byte off the original!

1st program (the original), 8 bytes

":P&r&H!

I know this isn't the smallest, but it is my first quine in Gol><> (I did it entirely on my own!). Link to the interpreter in the title!

Try it online!

Code Breakdown

":P&r&H!

First, the " command collects all of the chars and rewraps around the program

Then the : command doubles the last symbol in the program, the !

Then this is incremented, and saved by the register

The stack is then reversed and the value is put back

Then the entire stack is outputted as characters and then the program halts

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ you can use } to rotate the stack instead of &, Try it online! \$\endgroup\$ – Jo King Feb 5 '19 at 23:41
  • \$\begingroup\$ @JoKing wow, that cuts one byte off, thanks, is it okay if I put that as the answer (with credit to you of course) \$\endgroup\$ – KrystosTheOverlord Feb 5 '19 at 23:53
  • \$\begingroup\$ of course you can. PPCG is a lot about cooperative answers rather than competition and it's nice to help new users figure out shortcuts in their chosen language(s) \$\endgroup\$ – Jo King Feb 5 '19 at 23:58
  • \$\begingroup\$ @JoKing Thanks, credits are also to you! Are you a Gol><> coder, if you have any experience, do you have tips, I really like it! \$\endgroup\$ – KrystosTheOverlord Feb 6 '19 at 0:16
  • \$\begingroup\$ there's not really much Gol><> specific advice, but I would recommend getting familiar with its parent language, ><>, first. \$\endgroup\$ – Jo King Feb 6 '19 at 4:36
3
\$\begingroup\$

Attache, 69 57 53 41 bytes

Printf[s:="Printf[s:=%s,Repr@s]",Repr@s]

Try it online! Surprised I didn't think of this sooner.


Print!Format[x:="Print!Format[x:=%s,Repr!x]",Repr!x]

In the end, the standard quine framework was most efficient :( . The 57-byter below is significantly more interesting.

Try it online!

BUT I found a cooler one, also for 53 bytes!

Print!Join[q:=["Print!Join[q:=", ",Repr!q]"],Repr!q]

Try it online!

57 bytes

Print!Format<~_,Repr!_~>["Print!Format<~_,Repr!_~>[%s]"]

This uses sneaky curried functions with blanks. When a function is called using f<~...~> syntax, it denotes a curried function. _1 represents the first curried argument, _2 the second, etc. _ is an alias for _1, so this saves us some bytes without duplicating our string.

Try it online!

69 bytes

Save["Save[%c%s%c]Print[Format[_,34,_,34]]"]Print[Format[_,34,_,34]]

Try it online! The trailing newline is significant.

Explanation

Save updates the abstract variable _ with the string

"Save[%c%s%c]Print[Format[_,34,_,34]]"

Then, this string is formatted with the arguments _, 34, _, and 34. This prints the string, the character 34 (a quote), and then those two again, which is the program.

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

Fueue, 411 391 381 376 bytes

(5(2(7(1(8(0(0(4(0(2(5(2(4(9(9(0(4(9(0(2(4(2(8(2(1(6(9(0(6(2(9(5(9(5(9(0(1(1(4(0(3(2(3(1(3(1(9(1(8(1(1(1(0(1(4(0(1(2(3(1(3(1(7(1(6(1(9(0(4(9(9(5(8(2(4(9(9(0(4(9(4(9(1(6(9(0(4(9(1(0(1(6(4(9(9(5(4(9(9(0(4(9(4(9(1(6(9(0(4(9(6(2(9(5(9(0(3(1(3(1(4(9(1(1(0(2(6(1(3(1(3(1(0(2(4(2(9(0(4(9(6(2(1(6(4(9(1(6[10(:91(H49~)~48<]):[[)+$7--32+*$5--10)~[<~)~~])~!]~[~)~~])~:[)--~+40--48)~:]~]

Try it online!

See also Ørjan Johansen's answer.

Basic idea (outdated):

(7(1(9(5(1(1(8(0...                  Data.
[9!(91[+(H~)]57<33]                  Begin the second pass and end the program on second pass.
):[                                  Duplicate and evaluate the block.
    [)+$7--32+*$5--10)~[<~)~~])~!]   On the second pass, print b*10+a+32 for each two digits a, b.
    )()[~)~~]~:~<                    Copy a digit and evaluate the next line between copies.
    [)----40+--~)48~:~~]             Print "("+digit and duplicate and evaluate the whole block on the next digit.
]
| improve this answer | |
\$\endgroup\$
3
\$\begingroup\$

Golunar, 951 bytes (394.25 bytes as an integer value)

19370043316195921194914466480856680152267470323963447024756684537596068724128114478400203537500358028693578705195025299449504112473728653294217406768139954805008550643064305270958743186186490023003785512463398359429631224818444304976679217098389450981926661910005004089131207223929032173888419619738722341444212432611576207643452266161684471788295034889655803444137372629364500165719019777515305922257911642994836581634099155833200157295629218533465854143898419293035289733581625252699105530843807023973345521520887128012736565874423200184723012755626596238647926406709693583878890472621210970350861368171259284533764490596207310864352873729240842719608391238098412446205860013948766486129442046252306334230243913196704614648889659870117069927719874852423159076941049170045933025772364248625729725500550726133134993128102614696728457139079375133324957922066270555810085574853273966267981675757808791933974619299446035844180580831907739236954600685575

Golunar is the decimal representation of the number of zeros that a Unary code would need. It translates to this brainfuck code:

->+>+>+>>>>>>>>>>>>+>+>>>+>+>+>+>+>>>>>>+>>>+>>>+>>>+>>>+>>>+>>+>>>>+>+>>+>>>+>>>+>>>+>>>+>>>+>>>+>>>+>+>>>>>>>+>+>+>+>>>+>>>>+>+>+>>>+>+>+>>+>>+>>>+>+>+>+>+>+>>>>>+>+>+>>>+>+>+>>>>>>>>+>+>>>>>+>>+>>>+>>>+>+>>+>+>+>>+>>+>>>+>+>>>+>+>>+>+>+>+>>+>>>+>+>+>>>>>+>+>+>>>+>+>+>>>>>>>>+>+>>>>>>>+>+>+>+>>>+>>>>+>>+>+>+>+>+>>>>>>+>>+>>>>+>+>>>>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>>+>>>>+>>>+>>>>>>+>+>+>+>>>>>>+>>>+>>+>+>+>+>+>>>+>+>+>>>+>>>+>+>>+>+>>+>+>>+>+>>+>+>>+>+>>+>+>>+>+>>>>>>+>+>+>+>>+>>>>+>>>+>>>>>>+>+>+>+>>+>>>>+>>>+>>>>>>+>+>+>+>>+>>>>+>>>+>>>>>>+>+>+>+>>+>>>>+>>>+>>>>>>+>+>+>>>+>+>>>+>+>+>>>+>+>>+>+>+>>+>>+>>>+>+>>>+>+>>+>+>>+>>>+>>>>>>+>>>+>>>>>>+>>>+>>+>+>+>>>>>+>+>+>+>>>>>>+>>>>>>+>>+>+>+>>+>>+>>>+>>>+>+>+>+>>>>+>+>+>+>>+>>>+>>>+>+>+>>>>>+>+>>>>>>>+>+>+>+>+>>+>>>+>+>+>+>>>>+>+>>+>>>>>>+>>>+>>>>>>+>>+>+>+>>>>>+>+>>+>>>>>>>>>+>+>>+>+>>+>+[[>>+[>]+>++>+[<]<-]>>[>]<<-[<]<<+]+>+>-[>]++>++>++[[-<+]-<[-<[>++<-[>++<-[>++<-[>++<-[>--------<<[-]++>-[>++<-]]]]]]>[<+>-]+<<]>>[>>]<[>]<-[[-<+]-<<+>[>>]<[>]]<+]<[<<]>>[+++++++[<++++++>-]<.>>>]

Try it online!

I couldn't find an online Golunar interpreter, but you can use this Golunar to brainfuck converter to get the brainfuck code and then execute it.

This code is inspired by a brainfuck quine of Eric Bosman and Daniel B Cristofani. First it reads a list of bits that represent the bit-codes of the code part, then it builds up a list of bits that represent the ">" and "+" characters needed to print the first list. Those lists are merged and hold the binary value of the Golunar code. In the last step, the decimal value of the binary number are computed and printed.

[ 
tape: [decimal digits], value start marker/VS(-1)(starting cell), [input bits], between binary marker/BB(0), [binary output data]

input bits are 0 or 1, output bits are in reversed order and have the values 1(used) or 2(used and set)
input must be given in reversed order

decimal digits consist of two cells per value (value, digit used marker(DU)(1))

bit values:
> 000
< 001
+ 010
- 011
. 100
, 101
[ 110
] 111

]

-                       set VS

                    set input bits
>+>+>+>>>>>>>>>>>>+>+>>>+>+>+>+>+>>>>>>+>>>+>>>+>>>+>>>+>>>+>>+>>>>+>+>>+>>>+>>>+>>>+>>>+>>>+>>>+>>>
+>+>>>>>>>+>+>+>+>>>+>>>>+>+>+>>>+>+>+>>+>>+>>>+>+>+>+>+>+>>>>>+>+>+>>>+>+>+>>>>>>>>+>+>>>>>+>>+>>>+
>>>+>+>>+>+>+>>+>>+>>>+>+>>>+>+>>+>+>+>+>>+>>>+>+>+>>>>>+>+>+>>>+>+>+>>>>>>>>+>+>>>>>>>+>+>+>+>>>+>>
>>+>>+>+>+>+>+>>>>>>+>>+>>>>+>+>>>>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>+>>+>>>>+>>>+>>>>>>+>+>+>+>
>>>>>+>>>+>>+>+>+>+>+>>>+>+>+>>>+>>>+>+>>+>+>>+>+>>+>+>>+>+>>+>+>>+>+>>+>+>>>>>>+>+>+>+>>+>>>>+>>>+>
>>>>>+>+>+>+>>+>>>>+>>>+>>>>>>+>+>+>+>>+>>>>+>>>+>>>>>>+>+>+>+>>+>>>>+>>>+>>>>>>+>+>+>>>+>+>>>+>+>+>
>>+>+>>+>+>+>>+>>+>>>+>+>>>+>+>>+>+>>+>>>+>>>>>>+>>>+>>>>>>+>>>+>>+>+>+>>>>>+>+>+>+>>>>>>+>>>>>>+>>+
>+>+>>+>>+>>>+>>>+>+>+>+>>>>+>+>+>+>>+>>>+>>>+>+>+>>>>>+>+>>>>>>>+>+>+>+>+>>+>>>+>+>+>+>>>>+>+>>+>>>
>>>+>>>+>>>>>>+>>+>+>+>>>>>+>+>>+>>>>>>>>>+>+>>+>+>>+>

                    list rebuilding loop: append bits for "greater than" and plus symbols to the right of input data
+[                      for each input bit
  [                     while bit is greater than 0
    >>+                 copy bit to out data
    [>]+>++>+           append bits for plus (used markers plus 010)
    [<]<-               decrement in value
  ]
  >>[>]<<-              change most right character from plus to gt (010 to 000)
  [<]                   return to BB
  <<+                   repeat if not on VS
]
+>+>-                   prepare binary to decimal routine: set VS DU and first 1

[>]++>++>+              append bits for minus (011)

                    binary to decimal loop: use "double and add algorithm" to calculate the digits of the decimal value
+[                      if not on VS then
  [-<+]-                restore current bit value and go to VS
  <                     go to first DU
  [                 digit doubling loop
    -<                  remove DU and go to corresponding digit
    [
      >++<-             decrement current value and add 2 to temp value four times
      [
        >++<-
        [
          >++<-
          [
            >++<-
            [                   if value was greater than 4 then
              >---- ----        subtract 8 from temp
              <<[-]++           set next digit temp = 2 (DU plus 1)
              >-                decrement current digit
              [>++<-]           set temp = remaining value * 2
            ]
          ]
        ]
      ]
    ]
    >[<+>-]             set current digit = temp
    +                   set DU
    <<                  go to next digit
  ]                 end of digit doubling loop
  >>[>>]<[>]<           go to current bit
  -[                    if bit is 2 (used plus 1)
    [-<+]-              delete bit and go to VS
    <<+                 increment least significant digit
    >[>>]<[>]           go to current bit
  ]
  <+                    if not on VS then repeat  
]                   end of binary to decimal loop

<[<<]>                  go to most significant digit
>[                  printing loop: for each DU print corresponding value
  +++++++[<++++++>-]<.  add 48 to value (ASCII 0) and print
  >>>                   go to next DU
]
| improve this answer | |
\$\endgroup\$
3
\$\begingroup\$

Perl 5, 35 bytes

$_=q(print qq(\$_=q($_);eval));eval

Try it online!

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Welcome! Please consider adding an explanation or a link to an online interpreter. Code-only answers tend to be automatically flagged as low-quality. \$\endgroup\$ – mbomb007 Sep 20 '19 at 15:42
  • 1
    \$\begingroup\$ No problem. I didn't realize that tio.run has an area to copy/paste submission markdown for code golf. Very cool. \$\endgroup\$ – booshlinux Sep 20 '19 at 15:45
3
\$\begingroup\$

Tir, 24 bytes

Abandoned languages are my favorite.

«⤇℘↔»
⤇℘↔

Explanation

«⤇℘↔»       Push a string onto the stack. Stack: [⤇℘↔]
      ⤇      Duplicate TOS. Stack: [⤇℘↔,⤇℘↔]
        ℘    Make top of stack in its string-represented form. Stack: [⤇℘↔,«⤇℘↔»]
         ↔   Swap top two items in the stack. Stack: [«⤇℘↔»,⤇℘↔]
Stack will be implicitly outputted.
| improve this answer | |
\$\endgroup\$
3
\$\begingroup\$

FEU, 56 bytes

At first, I thought it was impossible.

Then I remembered __DATA__.

s/(.+)/\1\n__DATA__\n\1
__DATA__
s/(.+)/\1\n__DATA__\n\1

Try it online!

Explanation

It's just your usual quine. __DATA__ onwards is read and fed into the regex substitution, which takes the input, and puts it in this format:

input
__DATA__
input
| improve this answer | |
\$\endgroup\$
3
\$\begingroup\$

R, 44 41 bytes

crossed out 44 is still regular 44 ;(

-3 bytes thanks to Dominic van Essen

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

R, 41 bytes

`+` <-
function(x)cat(dump("+",""),1)
+ 1

Try it online!

This is 3 6 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
3
\$\begingroup\$

V, 4 bytes

2i2i

Try it online!

Explanation:

2       " Two times:
 i      " Insert the following:
  2i    " The string '2i'

This is pretty straightforward. In fact, this almost works in regular vim. There is just one minor thing in the way: The string '2i' isn't inserted twice until you hit <esc>. In V, this is solved by implicitly ending every program with an <esc> (Really, that's an oversimplification, but it's close enough to the truth).

Old versions of V always added a newline to the output, which is why I didn't post this earlier. However, in commit b6c238d, this was fixed.

This answer works just because of luck. The approach doesn't extend well to general purpose quines/quine-variations. The shortest quine I'm aware of that can be trivially modified is

ñéÑ~"qpÿ

Try it online!

Explanation:

ñ           " Start recording into register 'q'
 éÑ         " Insert 'Ñ' (uppercase so that the recording doesn't stop here)
   ~        " Toggle the case the character under the cursor (the 'Ñ')
    "qp     " Paste the contents of register 'q'
       ÿ    " Stop recording and play it all back

The reason the ÿ is needed, is because it is implicitly added to the end of macros, a feature that is unfortunate for quines, but very convenient for golf.

The nice thing about this quine is that we can do almost anything inside of the recording and it is still valid since it will be pasted later anyway.

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

Pushy, 9 bytes

95 34
_"

Although writing functional programs in Pushy is sometimes difficult, the quine is relatively simple:

95   % Push 95 to the stack (ASCII code for _ )
34   % Push 34 to the stack (ASCII code for " )
_    % Print representation of the stack: 95 34
"    % Print stack converted to string: _"

Notice that, although Pushy ignores newlines, it is needed here because the default separator for printing is \n - and there needs to be a trailing newline, hence making it 9 bytes


Alternatively, an 11-byte solution that does not require a newline:

78 95 34N_"

Works similarly to the one above, but N sets the separator an empty string.

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

2DFuck, 963 853 bytes

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

Try it online!

Just a plain binary encoding beats out the huffman style encoding.

Explanation

!x^           Leave a marker at the start of the data string
x>>x>x>...    Push a binary string where 'x>' is 1 and '>' is 0
v[<r!x]       Move to the start of the data string
..!.!....!.   Print the leading '!'
<^x           Add a leading 1 bit to the data string
[             Loop over the data string
  r[!.!....!...]     If the current bit is a 1, print 'x'
  v.r!.!.vr^!....!.  Print a '^' if the current bit is the first bit, else '>'
  >r^                Move to the next bit
]
![            Loop over the data string in reverse
  r.v<r^        Print each bit of the data string
]

And my previous longer but more interesting answer below:

2DFuck, 963 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!..!.!....!.!.!....!....!...!.!..!.![<r!]![vr[!.!....!...]..!.....!.>^r!].![vr[!.!.!.<r!...!.>r!]r![<r[<r.>r..<r!..!.>r!.]r![<r[.!.!..<r.!.>r.!]r![<r[<r.!.>r.!]!...r![<r.!..>r].]]]<<^r.!]

Try it online!

I'm glad I got this below 1000 bytes. I think it still could be shorter though, maybe through encoding multiple or partial characters rather than one character per binary string. In particular encoding .. and/or !. as tokens but while that may make the data string shorter, the increases to the decoder may not be worth it. Here's the helper program to generate the program.

Explanation

!xv                Leave a marker at the start of the data string
>x>x>>>x>...       Create the binary data string where 'x>' is 1 and '>' is 0
                   Here we encode the characters of the program as
     '.' => 10
     '!' => 11
     '<' => 010
     'r' => 011
     '[' => 0010
     ']' => 0011
     '>' => 00010
     '^' => 00011
     'v' => 00000
     'x' => 00001

^x                 Leave a marker at the end of the data string
!..!.!....!.       Print '!xv'
!.!....!...
.!...!.!..!.

![<r!]             Move to the start of the data string
![                 Loop over each bit of the data string
  vr[!.!....!...]    Print an 'x' if the bit is 1
  ..!.....!.         Print a '>'
>^r!]

.!                 Print a zero bit for use in the first character
[                  Loop over the data string in reverse
  vr[                If the current bit is a 1, print 
    !.!.!.<r!...!.>r!  '.' if the next bit is a 0, otherwise '!'
  ]
  r![                Otherwise
    <r[                If the next bit is a 1, print
      <r.>r..<r!..!.>r!. '<' if the next bit is a 0, otherwise 'r'
    ]
    r![                Otherwise
      <r[                If the next bit is a 1, print
        .!.!..<r.!.>r.!    '[' if the next bit is a 0, otherwise ']'
      ]
      r![                Otherwise
        <r[<r.!.>r.!]!...  Print '>','^','v' or 'x' based on the next two bits
        r![<r.!..>r].
      ]
    ]
  ]
  <<^r            Move to the next bit in the data string
  .!              And print a zero bit for the next character
]
| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

Java (229 Characters)

class Main{public static void main(String[]args){char q='"';String s="class Main{public static void main(String[]args){char q='%c';String s=%c%s%c;System.out.print(s.format(s,q,q,s,q));}}";System.out.print(s.format(s,q,q,s,q));}}
| improve this answer | |
\$\endgroup\$
  • 4
    \$\begingroup\$ You can shorten it by naming your class a one character name (such as q for quine). Also, there is no need for main(String[]args), just do something like main(String[]a) (total savings: 6 chars) \$\endgroup\$ – Justin Dec 11 '13 at 23:51
  • \$\begingroup\$ @Justin Technically, 12 bytes saving. \$\endgroup\$ – driima Nov 1 '16 at 8:59
2
\$\begingroup\$

Haskell, 93 68 characters

s="\nmain=putStrLn$\"s=\"++show s++s"
main=putStrLn$"s="++show s++s
| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

Bash, 67/51 chars

f () 
{ 
    printf "%s\n${!1} $1" "$(local -f ${!1})"
}
f FUNCNAME

And 51 chars:

trap -- 'printf "%s\n:" "$(trap -p DEBUG)"' DEBUG
:
| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

Zozotez Lisp: 73

((\ (x) (c x (c (c (" ") (c x))))) (" (\ (x) (c x (c (c (" ") (c x)))))))

This requires one of the REPLs. For one bootstrap expression quine I need it to print: 81

((\ (x) (p (c x (c (c (" ") (c x)))))) (" (\ (x) (p (c x (c (c (" ") (c x))))))))

Extended BrainFuck: 68

This uses mostly Brainfuck code except for the store string procedure.

>~"~!<<.[<]>.>+.-<[.>]<[<]>>+.->[.>]"<<.[<]>.>+.-<[.>]<[<]>>+.->[.>]

A 94 byte version that uses more EBF features:

{c|"{q$q.$p(-)}:q:p$q 34+$p|'{c|'&q&c&q|'}'(-)&c"}{q$q.$p(-)}:q:p$q 34+$p|'{c|'&q&c&q|'}'(-)&c
| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

Node.js REPL (22)

console.log(RegExp.$1)
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ ...this abuses the fact that (I guess) the Node REPL internally executes a regex on the received line? I want to upvote because of the cleverness, but on the other hand I don't want to since it relies on extracting its own source code as a string... \$\endgroup\$ – FireFly Aug 22 '14 at 15:38
  • \$\begingroup\$ You need to specify the Node version this works in, because running in 7.5.0, this prints a single newline. \$\endgroup\$ – Patrick Roberts Jul 16 '17 at 5:21
2
\$\begingroup\$

MATLAB, 95 characters

There might be shorter ones, but I'm happy that it works at all.

function d=g();d='gvodujpo!e>h)*<e>(<e>\e)2;29*.2-e-e)29;foe*.2^<';d=[d(1:18)-1,d,d(18:end)-1];

Cleaner approach, exact same length:

function d=g();d='function d=g();d=[d(1:17),39,d,39,d(15:end)];';d=[d(1:17),39,d,39,d(15:end)];
| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

Burlesque - 1 byte

Technically, this is a quine:

1

Technically, this is also a quine:

{1 2 3}

Pretty much any literal is a quine.

This is also a quine which doesn't use a simple literal:

,#Q2 SH ~- ",#Q" \/ .+ sh

The comma is not necessary if you launch burlesque in no-stdin mode.

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

AppleScript, 2 Bytes

1

It's a little cheaty, but it is following the restrictions of a quine. If we don't count the trailing newline, then this solution becomes 1 byte - 1.

Whenever AppleScript has a final executed line of code, it prints the result of the last operation (whatever it is) to the command line.

text

Any class name has the same effect.

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

DUP, 51 bytes

0"0.[34,0[$;$][,1+]#]$!%%!"0.[34,0[$;$][,1+]#]$!%%!

Try it here.

Well, DUP quines are possible, just really, really, long. I'll have to golf some more.

| improve this answer | |
\$\endgroup\$
1
5 6
7
8 9
13

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.