241
\$\begingroup\$

Using your language of choice, golf a quine.

A quine is a non-empty computer program which takes no input and produces a copy of its own source code as its only output.

No cheating -- that means that you can't just read the source file and print it. Also, in many languages, an empty file is also a quine: that isn't considered a legit quine either.

No error quines -- there is already a separate challenge for error quines.

Points for:

  • Smallest code (in bytes)
  • Most obfuscated/obscure solution
  • Using esoteric/obscure languages
  • Successfully using languages that are difficult to golf in

The following Stack Snippet can be used to get a quick view of the current score in each language, and thus to know which languages have existing answers and what sort of target you have to beat:

var QUESTION_ID=69;
var OVERRIDE_USER=98;

var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";var COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk";var answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;function answersUrl(index){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+index+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}
function commentUrl(index,answers){return"https://api.stackexchange.com/2.2/answers/"+answers.join(';')+"/comments?page="+index+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}
function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(data){answers.push.apply(answers,data.items);answers_hash=[];answer_ids=[];data.items.forEach(function(a){a.comments=[];var id=+a.share_link.match(/\d+/);answer_ids.push(id);answers_hash[id]=a});if(!data.has_more)more_answers=!1;comment_page=1;getComments()}})}
function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(data){data.items.forEach(function(c){if(c.owner.user_id===OVERRIDE_USER)
answers_hash[c.post_id].comments.push(c)});if(data.has_more)getComments();else if(more_answers)getAnswers();else process()}})}
getAnswers();var SCORE_REG=(function(){var headerTag=String.raw `h\d`
var score=String.raw `\-?\d+\.?\d*`
var normalText=String.raw `[^\n<>]*`
var strikethrough=String.raw `<s>${normalText}</s>|<strike>${normalText}</strike>|<del>${normalText}</del>`
var noDigitText=String.raw `[^\n\d<>]*`
var htmlTag=String.raw `<[^\n<>]+>`
return new RegExp(String.raw `<${headerTag}>`+String.raw `\s*([^\n,]*[^\s,]),.*?`+String.raw `(${score})`+String.raw `(?=`+String.raw `${noDigitText}`+String.raw `(?:(?:${strikethrough}|${htmlTag})${noDigitText})*`+String.raw `</${headerTag}>`+String.raw `)`)})();var OVERRIDE_REG=/^Override\s*header:\s*/i;function getAuthorName(a){return a.owner.display_name}
function process(){var valid=[];answers.forEach(function(a){var body=a.body;a.comments.forEach(function(c){if(OVERRIDE_REG.test(c.body))
body='<h1>'+c.body.replace(OVERRIDE_REG,'')+'</h1>'});var match=body.match(SCORE_REG);if(match)
valid.push({user:getAuthorName(a),size:+match[2],language:match[1],link:a.share_link,})});valid.sort(function(a,b){var aB=a.size,bB=b.size;return aB-bB});var languages={};var place=1;var lastSize=null;var lastPlace=1;valid.forEach(function(a){if(a.size!=lastSize)
lastPlace=place;lastSize=a.size;++place;var answer=jQuery("#answer-template").html();answer=answer.replace("{{PLACE}}",lastPlace+".").replace("{{NAME}}",a.user).replace("{{LANGUAGE}}",a.language).replace("{{SIZE}}",a.size).replace("{{LINK}}",a.link);answer=jQuery(answer);jQuery("#answers").append(answer);var lang=a.language;lang=jQuery('<i>'+a.language+'</i>').text().toLowerCase();languages[lang]=languages[lang]||{lang:a.language,user:a.user,size:a.size,link:a.link,uniq:lang}});var langs=[];for(var lang in languages)
if(languages.hasOwnProperty(lang))
langs.push(languages[lang]);langs.sort(function(a,b){if(a.uniq>b.uniq)return 1;if(a.uniq<b.uniq)return-1;return 0});for(var i=0;i<langs.length;++i)
{var language=jQuery("#language-template").html();var lang=langs[i];language=language.replace("{{LANGUAGE}}",lang.lang).replace("{{NAME}}",lang.user).replace("{{SIZE}}",lang.size).replace("{{LINK}}",lang.link);language=jQuery(language);jQuery("#languages").append(language)}}
body{text-align:left!important}#answer-list{padding:10px;float:left}#language-list{padding:10px;float:left}table thead{font-weight:700}table td{padding:5px}
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/Sites/codegolf/primary.css?v=f52df912b654"> <div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td><a href="{{LINK}}">{{SIZE}}</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td><a href="{{LINK}}">{{SIZE}}</a></td></tr></tbody> </table> 

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

444 Answers 444

1
6 7
8
9 10
15
3
\$\begingroup\$

Threead, 24 bytes

">34co<o>o<o">34co<o>o<o

Try it online!

I didn't think to do it like this until I saw Riley's answer. I have no intention to self-award the bounty, so this is non-competitive for it.

Explanation

">34co<o>o<o">34co<o>o<o
">34co<o>o<o"               # Encodes the right half of the program as a string, in the 1st buffer.
             >              # Move to the 2nd buffer.
              34c           # Put the string represented by ascii 34 (") in the second buffer.
                 o          # Write it to STDOUT
                  <o        # Move to the 1st buffer, Write the contents of the string to STDOUT.
                    >o      # Move back to the 2nd Buffer, write it.
                      <o    # Move back to the 1st Buffer, write it.

Originally... 129 Bytes...

My plan was to use:

"\x0E\x0E\x0E78g\x0EBv$/s@$@c8$$$$$vB\x0Ep$/c6Bb_$f$vgs@$/Bba\x0E$$$c5$$$$$1c5$$$$p"

34c
>r +o< <_4     r>
l +_2>^[ b rco< +>^]
   _1     -_1    l

where \x0E is the literal SOH.

Try it online!

The string is simply all the commands after it, but with a byte value 4 higher. This was because I can't store a " or a \ in the string, without it getting meta. The rest of the script, acts kind of like my other solution, however manually iterates through the string, printing each character -4.

\$\endgroup\$
5
  • 2
    \$\begingroup\$ "I have no intention to self-award the bounty." You can't. \$\endgroup\$ Jan 13, 2017 at 9:10
  • 4
    \$\begingroup\$ The README on github doesn't seem to mention that you can push string literals. \$\endgroup\$
    – Riley
    Jan 13, 2017 at 14:58
  • \$\begingroup\$ @Riley True, but you can figure that out by looking at the Threead "Hello, World!" program. \$\endgroup\$
    – mbomb007
    Jan 13, 2017 at 21:56
  • \$\begingroup\$ Question, how does string multiplication work? I was trying to get it to work on TIO (to solve your bounty), and I couldn't figure it out. \$\endgroup\$
    – mbomb007
    Jan 13, 2017 at 22:00
  • 1
    \$\begingroup\$ @mbomb007 Hopefully this will help you out. And Riley sorry about that, the readme was kind of poorly written. \$\endgroup\$
    – ATaco
    Jan 14, 2017 at 4:41
3
\$\begingroup\$

Befunge-93, 17 bytes

Thanks to James Holderness for pointing out that this relies on nonstandard interpreter behavior

Slightly late to the party, but here goes!

<@,*2+98_,#! #:<"

Try it here, but you have to copy-paste the code. The program relies on nonstandard interpreter behavior, so it'll print a bunch of leading spaces on TIO. Oops. My bad.

<: sets the program direction to "left"; instruction pointer wraps around

": toggles string mode (pushes ascii value of every character until next ", which it encounters only when it wraps around)

(at this point, it pushes every character to the stack & wraps around. This is where it relies on nonstandard behavior - TIO and the reference interpreter would push a bunch of spaces to the stack)

:<: sets the instruction pointer direction to "left" and duplicates top of stack

! #: negates the value at the top (important because of the upcoming _); # skips the next character

_,#: checks the value at the top of the stack & pops it: prints the ascii value as a character of the new top and sets the direction of the instruction pointer to right if checked character was 0; else sets the direction of the instruction pointer to left

@,*2+98: prints the " at the end of the program and quits.

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

Alice, 9 bytes

Credits to Sp3000 for the idea of including the !.

"!<@o&9h.

Try it online!

Explanation

This works much like quines in other Fungeoids with an unmatched " that wraps the entire code (except itself) in a string because the instruction pointer move cyclically through the code.

"!<@o&9h."   Push code points of the entire program except the " to the
             stack (irrelevant).
!            Store 46 (the code point of '.') on the tape (irrelevant).
<            Send IP back west.
!            Store 104 (the code point of 'h') on the tape (irrelevant).
".h9&o@<!"   Push code points of the entire program except the " to the
             stack in reverse.
.            Duplicate the 33 (the code point of '!').
h            Increment to 34 (the code point of '"').
             Now the top nine values on the stack correspond to the entire
             code in reverse order.
9&           Repeat the next command 9 times.
o            Print 9 characters from the top of the stack.
@            Terminate the program.
\$\endgroup\$
3
\$\begingroup\$

dc, 16 bytes

[91Pn6120568P]dx

Try it online!

Nothing fancy, posting for completeness.

Explanation

[91Pn6120568P]dx
 91P              # Print "["
    n             # Print the macro
     6120568P     # Print "]dx" encoded as a number
[            ]dx  # Run macro on its own code
\$\endgroup\$
3
\$\begingroup\$

Excel, 131 bytes

=SUBSTITUTE("=SUBSTITUTE(@,CHAR(64),CHAR(34)&@&CHAR(34))",CHAR(64),CHAR(34)&"=SUBSTITUTE(@,CHAR(64),CHAR(34)&@&CHAR(34))"&CHAR(34))

Adapted from a program by Dave Burt.

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

Go, 112 bytes

As far as I can tell, there's no Go answer here. Here's mine and I think this is the shortest possible.

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

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ 80 bytes by turning it into a called function. \$\endgroup\$
    – bigyihsuan
    Nov 2, 2022 at 19:12
3
\$\begingroup\$

Kotlin, 121 bytes

Nobody cared enough about Kotlin to post it so...

fun main(a:Array<String>){val s="fun main(a:Array<String>){val s=%c%s%1$1c;print(s.format(34,s))}";print(s.format(34,s))}

Try it online!

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

Groovy, 48 bytes

The language's pretty groovy too.

s="s=%c%s%c;printf(s,34,s,34)";printf(s,34,s,34)

Try it online!

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

Octave, 28 bytes

Note: This doesn't work on TIO. I guess it's because TIO doesn't store the command history. It works on the desktop version. I tried it in Octave 4.2.1.


printf('%s',[history(1){:}])

So, what's going on here?

history is a function that can be used to read and manipulate the command history.

history(n) shows the n most recent commands you have typed, numbered:

>> x = 1 + 2;
>> y = x * 3;
>> history(3)
    7 x = 1 + 2;
    8 y = x * 3;
    9 history(3)

As you can see, x = 1 + 2 was the seventh command that was typed after the history was cleared the last time. The command history(3) is included in this list.

Now, history(1) is not a quine, since it gives:

>> history(1)
   10 history(1)

However, if you assign the output from history(1) to an output, you'll get:

>> x = history(1)
x =
{
  [1,1] = x = history(1)
}

It's still not a quine, but it's something we can work with.

Unwrapping this, and we're a bit closer:

>> [history(1){:}]
ans = [history(1){:}]

Notice that the entire command, including brackets are outputted.

Finally, if we print this as a string, using printf, we get:

>> printf('%s',[history(1){:}])
printf('%s',[history(1){:}])

Note: disp([history(1){:}]) almost works, but it appends a trailing newline.

\$\endgroup\$
1
  • \$\begingroup\$ Wouldn't disp([history(1){:}])\n work for 27 bytes? \$\endgroup\$ Aug 29, 2017 at 14:47
3
\$\begingroup\$

DipDup, 6 bytes

[_:]_:

Try it online!

Explanation

[_:]        push this list
    _       duplicate
     :      cons
\$\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.
\$\endgroup\$
1
  • \$\begingroup\$ An interesting 8 byter using S" \$\endgroup\$
    – Jo King
    Nov 28, 2018 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
\$\endgroup\$
7
  • \$\begingroup\$ I take it that it would not be shorter to do &D after t, avoiding U? \$\endgroup\$ Oct 23, 2016 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, 2016 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\$ Oct 23, 2016 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, 2016 at 3:08
  • \$\begingroup\$ Yeah, that's what I meant, and that's what I figured \$\endgroup\$ Oct 23, 2016 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.

\$\endgroup\$
2
  • \$\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, 2018 at 13:59
  • \$\begingroup\$ Alright, that's the one on TIO so I tried with that sorry! Nvm, in that case. \$\endgroup\$ Aug 11, 2018 at 14:01
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...
\$\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!

\$\endgroup\$
1
  • \$\begingroup\$ Ha, didn't even see prior to posting this and you already beat me. Very clever use of the multiple IP feature. \$\endgroup\$ Oct 1, 2018 at 18:22
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

\$\endgroup\$
7
  • \$\begingroup\$ you can use } to rotate the stack instead of &, Try it online! \$\endgroup\$
    – Jo King
    Feb 5, 2019 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\$ Feb 5, 2019 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, 2019 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\$ Feb 6, 2019 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, 2019 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.

\$\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.
]
\$\endgroup\$
3
\$\begingroup\$

Perl 5, 35 bytes

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

Try it online!

\$\endgroup\$
2
  • \$\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, 2019 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, 2019 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.
\$\endgroup\$
3
\$\begingroup\$

Wren, 287 bytes

var a="[118,97,114,32,97,61,34].each{|m|System.write(String.fromCodePoint(m))}
System.write(a+String.fromCodePoint(34)+String.fromCodePoint(10)+a)"
[118,97,114,32,97,61,34].each{|m|System.write(String.fromCodePoint(m))}
System.write(a+String.fromCodePoint(34)+String.fromCodePoint(10)+a)

Try it online!

Explanation

var a=                                                                         // Define the variable a
      "[118,97,114,32,97,61,34].each{|m|System.write(String.fromCodePoint(m))}
System.write(a+String.fromCodePoint(34)+String.fromCodePoint(10)+a)"           // As the string that processes the variable

                                                                               // A literal newline is inserted and can be decoded literally.

[118,97,114,32,97,61,34].each{|m|System.write(String.fromCodePoint(m))}        // Output the string "var a=" to the console
System.write(                                                                  // Output without a newline:
             a                                                                 // The string a
              +String.fromCodePoint(34)                                        // Plus a quote
                                       +String.fromCodePoint(10)               // Plus a newline
                                                                +a)            // Plus the string again
```
\$\endgroup\$
3
  • 1
    \$\begingroup\$ Why doesn't fromByte work in place of fromCodePoint? \$\endgroup\$
    – Jo King
    Oct 29, 2019 at 23:28
  • \$\begingroup\$ I have absolutely no idea. \$\endgroup\$
    – user85052
    Oct 30, 2019 at 3:57
  • \$\begingroup\$ @JoKing It does work ;) \$\endgroup\$
    – DialFrost
    Nov 8, 2022 at 1:59
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
\$\endgroup\$
3
\$\begingroup\$

!@#$%^&*()_+, 38 bytes

4K6j364K3645/1,3(!&$*)+(@)+(_+@)

Try it online!

Uses quite a few unprintables to abuse the behaviour of pushing the ordinal value of that character.

Explanation:

4K6j364K3645/1,3                           Push data section to stack   (0,data)
                                           Push zero, then the counter  (0,data,0,19)
                    (!&$*)                   Push the reverse of the data (0,data,0,atad,0)
                          +(@)               Print the data               (0,data,0)
                              +(_+@)        Print the data again, in reverse and offset by 11
\$\endgroup\$
0
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.

\$\endgroup\$
0
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
]
\$\endgroup\$
3
\$\begingroup\$

2sable, 10 bytes

44186D15B

Try it online!

This uses the same strategy as its parent language 05AB1E, but beats it by not having to join afterwards.

Explanation

44186      Push 44186
     D     Duplicate
      15B  Convert to base 15
           Implicitly print the stack
\$\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).

`+` <-
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.

\$\endgroup\$
15
  • 1
    \$\begingroup\$ IIRC TIO calls R by using Rscript as seen here, not sure if that's the difference. \$\endgroup\$
    – Giuseppe
    Aug 4, 2020 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\$ Aug 4, 2020 at 17:51
  • \$\begingroup\$ @DominicvanEssen Neat, thanks! \$\endgroup\$ Aug 4, 2020 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, 2020 at 22:03
  • \$\begingroup\$ @Giuseppe Thanks for working that out! \$\endgroup\$ Aug 5, 2020 at 5:39
3
\$\begingroup\$

Jq -rn, 18 bytes

"|@json+."|@json+.
"|@json+."         # the string
          |        # through the filter
           @json   # json encoded
                +  # concatenated with
                 . # itself
\$\endgroup\$
3
\$\begingroup\$

05AB1E, 13 bytes

"34çì«"34çì«

Try it online!

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

Vyxal, 10 8 bytes

`:qp`:qp

Try it Online!

-2 thanks to a stone arachnid

Explained

`:qp`:qp
`:qp`    # the string ":qp"
     :q  # surrounded in backticks
       p # and prepended to itself
\$\endgroup\$
3
  • 2
    \$\begingroup\$ 8 bytes: Try it Online! \$\endgroup\$ May 26, 2021 at 3:43
  • \$\begingroup\$ Does this count? \$\endgroup\$
    – user
    May 30, 2021 at 16:13
  • 1
    \$\begingroup\$ @user no, it doesn't \$\endgroup\$
    – lyxal
    May 30, 2021 at 22:30
1
6 7
8
9 10
15

Your Answer

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

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